Task: | Sokkelo |
Sender: | Anttono |
Submission time: | 2022-01-22 14:32:38 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 1, 2 | details |
#3 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.11 s | 2 | details |
#5 | ACCEPTED | 0.11 s | 2 | details |
#6 | WRONG ANSWER | 0.09 s | 2 | details |
#7 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#8 | WRONG ANSWER | 0.10 s | 2 | details |
#9 | ACCEPTED | 0.09 s | 2 | details |
#10 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#11 | WRONG ANSWER | 0.10 s | 2 | details |
#12 | ACCEPTED | 0.01 s | 1, 2 | details |
#13 | ACCEPTED | 0.10 s | 2 | details |
#14 | ACCEPTED | 0.01 s | 1, 2 | details |
#15 | ACCEPTED | 0.10 s | 2 | details |
#16 | ACCEPTED | 0.01 s | 2 | details |
#17 | ACCEPTED | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> using namespace std; const int N = 1002; const int inf = 1e9; int n,m; int r = inf; int v[N][N]; void f(int x, int y) { if(v[x][y] != 1) return; v[x][y] = 2; f(x+1, y); f(x, y+1); f(x-1, y); f(x, y-1); } void fr(int x, int y) { queue<pair<pair<int,int>,int>> q; q.push({{x,y},0}); while(!q.empty()) { auto e = q.front(); q.pop(); int x = e.first.first; int y = e.first.second; int dist = e.second; if(x<=0 || y<=0 || x>n || y>m) continue; if(dist > 0 || v[x][y] == 0) { dist++; if(v[x][y] == 0) { v[x][y] = 3; q.push({{x+1, y}, dist}); q.push({{x, y+1}, dist}); q.push({{x-1, y}, dist}); q.push({{x, y-1}, dist}); } else if(v[x][y] == 2) { r = min(r, dist); } } else if(v[x][y] == 1) { v[x][y] = 3; q.push({{x+1, y}, 0}); q.push({{x, y+1}, 0}); q.push({{x-1, y}, 0}); q.push({{x, y-1}, 0}); } } } int main() { cin>>n>>m; char c; pair<int,int> kv; pair<int,int> jt; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>c; v[i][j] = (c != '#' ? 1 : 0); if(c == 'A') kv = {i,j}; if(c == 'B') jt = {i,j}; } } f(kv.first, kv.second); fr(jt.first, jt.second); if(r == inf) r = 1; cout<<r; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 3
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
9 |
user output |
---|
15 |
Test 4
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
1 |
Test 5
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 6
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
335 |
user output |
---|
668 |
Test 7
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #####.############## ###.....############ ##.......########### ... |
correct output |
---|
10 |
user output |
---|
11 |
Test 8
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
436 |
user output |
---|
518 |
Test 9
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 10
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #B................## #################.## #################.## ... |
correct output |
---|
2 |
user output |
---|
5 |
Test 11
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
3 |
Test 12
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 14
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
502 |
user output |
---|
502 |
Test 16
Group: 2
Verdict: ACCEPTED
input |
---|
3 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
1 |
Test 17
Group: 2
Verdict: ACCEPTED
input |
---|
1000 3 ### #A# #.# #.# ... |
correct output |
---|
1 |
user output |
---|
1 |