Task: | Sokkelo |
Sender: | Mahtimursu |
Submission time: | 2022-01-22 13:46:40 +0200 |
Language: | C++ (C++17) |
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 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#3 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.06 s | 2 | details |
#5 | WRONG ANSWER | 0.12 s | 2 | details |
#6 | WRONG ANSWER | 0.11 s | 2 | details |
#7 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#8 | WRONG ANSWER | 0.10 s | 2 | details |
#9 | WRONG ANSWER | 0.09 s | 2 | details |
#10 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#11 | WRONG ANSWER | 0.10 s | 2 | details |
#12 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#13 | WRONG ANSWER | 0.09 s | 2 | details |
#14 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#15 | WRONG ANSWER | 0.09 s | 2 | details |
#16 | ACCEPTED | 0.01 s | 2 | details |
#17 | ACCEPTED | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> typedef long long ll; #define M 1000000007 #define N (1 << 18) using namespace std; string mp[1001]; bool vis[1001][1001]; bool vis2[1001][1001]; int dst[1001][1001]; int dirs[4][2] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} }; void dfs(int y, int x) { if (vis[y][x]) return; vis[y][x] = 1; for (int k = 0; k < 4; ++k) { int ny = y + dirs[k][0]; int nx = x + dirs[k][1]; if (mp[ny][nx] != '#') { dfs(ny, nx); } } } void dfs2(int y, int x) { if (vis2[y][x]) return; vis2[y][x] = 1; for (int k = 0; k < 4; ++k) { int ny = y + dirs[k][0]; int nx = x + dirs[k][1]; if (mp[ny][nx] != '#') { dfs2(ny, nx); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> mp[i]; } pair<int, int> a = {-1, -1}; pair<int, int> b = {-1, -1}; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (mp[i][j] == 'A') { a = {i, j}; } else if (mp[i][j] == 'B') { b = {i, j}; } } } dfs(a.first, a.second); if (vis[b.first][b.second]) { cout << 1 << "\n"; return 0; } queue<pair<int, int>> q; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (!vis[i][j]) { dst[i][j] = 1e9; } else { q.push({i, j}); } cout << (dst[i][j] == 0 ? 0 : 1); } cout << endl; } while (!q.empty()) { auto p = q.front(); q.pop(); int x = p.second; int y = p.first; for (int k = 0; k < 4; ++k) { int nx = x + dirs[k][1]; int ny = y + dirs[k][0]; if (nx >= 0 && ny >= 0 && nx < m && ny < n && dst[y][x] + 1 < dst[ny][nx]) { dst[ny][nx] = dst[y][x] + 1; q.push({ny, nx}); } } } dfs2(b.first, b.second); int ans = 1e9; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (vis2[i][j]) { ans = min(ans, dst[i][j]); //cout << i << ", " << j << endl; } } } if (ans > n * m || ans < 2) exit(-1); cout << ans << "\n"; return 0; }
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: WRONG ANSWER
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
2 |
user output |
---|
11111111111111111111 10000000000000000001 10000000000000000001 10000000000000000001 100000 ... Truncated |
Test 3
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
9 |
user output |
---|
11111111111111111111 10000000000000000001 10000000000000000001 10000000000000000001 100000 ... Truncated |
Test 4
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
1 |
Test 5
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 6
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
335 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 7
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #####.############## ###.....############ ##.......########### ... |
correct output |
---|
10 |
user output |
---|
11111111111111111111 11111011111111111111 11100000111111111111 11000000011111111111 110000 ... Truncated |
Test 8
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
436 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 9
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 10
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### #B................## #################.## #################.## ... |
correct output |
---|
2 |
user output |
---|
11111111111111111111 11111111111111111111 11111111111111111111 11111111111111111111 111000 ... Truncated |
Test 11
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 12
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
2 |
user output |
---|
11111111111111111111 11111111110111111111 11111111110111111111 11111111110111111111 111111 ... Truncated |
Test 13
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
111111111111111111111111111111... Truncated |
Test 14
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
12 |
user output |
---|
11111111111111111111 11111111110111111111 11111111110111111111 11111111110111111111 111111 ... Truncated |
Test 15
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
502 |
user output |
---|
111111111111111111111111111111... Truncated |
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 |