| Task: | Sokkelo |
| Sender: | MojoLake |
| Submission time: | 2022-01-22 13:48:37 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 28 |
| #2 | ACCEPTED | 72 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2 | details |
| #3 | ACCEPTED | 0.01 s | 1, 2 | details |
| #4 | ACCEPTED | 0.11 s | 2 | details |
| #5 | ACCEPTED | 0.07 s | 2 | details |
| #6 | ACCEPTED | 0.05 s | 2 | details |
| #7 | ACCEPTED | 0.01 s | 1, 2 | details |
| #8 | ACCEPTED | 0.04 s | 2 | details |
| #9 | ACCEPTED | 0.04 s | 2 | details |
| #10 | ACCEPTED | 0.01 s | 1, 2 | details |
| #11 | ACCEPTED | 0.04 s | 2 | details |
| #12 | ACCEPTED | 0.01 s | 1, 2 | details |
| #13 | ACCEPTED | 0.03 s | 2 | details |
| #14 | ACCEPTED | 0.01 s | 1, 2 | details |
| #15 | ACCEPTED | 0.03 s | 2 | details |
| #16 | ACCEPTED | 0.01 s | 2 | details |
| #17 | ACCEPTED | 0.01 s | 2 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:47:24: warning: 'bx' may be used uninitialized in this function [-Wmaybe-uninitialized]
dfs(ay, ax, 0); dfs(by, bx, 1);
~~~^~~~~~~~~~~
input/code.cpp:47:8: warning: 'ay' may be used uninitialized in this function [-Wmaybe-uninitialized]
dfs(ay, ax, 0); dfs(by, bx, 1);
~~~^~~~~~~~~~~
input/code.cpp:47:8: warning: 'ax' may be used uninitialized in this function [-Wmaybe-uninitialized]
input/code.cpp:47:24: warning: 'by' may be used uninitialized in this function [-Wmaybe-uninitialized]
dfs(ay, ax, 0); dfs(by, bx, 1);
~~~^~~~~~~~~~~Code
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = (int)1e5;
const int inf = (int)1e8;
bool grid[1000][1000];
bool vis[1000][1000][2];
void dfs(int y, int x, bool b){
//cout << y << " " << x << "\n";
vis[y][x][b] = 1;
if(grid[y+1][x]&&!vis[y+1][x][b])dfs(y+1, x, b);
if(grid[y-1][x]&&!vis[y-1][x][b])dfs(y-1, x, b);
if(grid[y][x+1]&&!vis[y][x+1][b])dfs(y, x+1, b);
if(grid[y][x-1]&&!vis[y][x-1][b])dfs(y, x-1, b);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
int ay, ax, by, bx;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
char c; cin >> c;
if(c=='#')grid[i][j]=0;
else grid[i][j] = 1;
if(c=='A'){
ay = i;
ax = j;
}
else if(c=='B'){
by = i;
bx = j;
}
}
}
dfs(ay, ax, 0); dfs(by, bx, 1);
ll closestA[n][m];
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(vis[i][j][0])closestA[i][j]=0;
else closestA[i][j] = inf;
//cout << closestA[i][j] << " ";
}
}
for(int i = 1; i < n - 1; ++i){
for(int j = 1; j < m - 1; ++j){
if(!vis[i][j][0]){
closestA[i][j] = min(closestA[i][j], min(closestA[i+1][j], min(closestA[i-1][j], min(closestA[i][j+1], closestA[i][j-1])))+1);
}
//cout << closestA[i][j] << " ";
}
}
ll ans = inf;
for(int i = 1; i < n-1; ++i){
for(int j = 1; j < m - 1; ++j){
if(!vis[i][j][1])continue;
else ans = min(ans, closestA[i][j]);
}
}
if(!ans)cout << "1\n";
else 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: ACCEPTED
| input |
|---|
| 20 20 #################### #A.................# #..................# #..................# ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 3
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 20 20 #################### #A.................# #..................# #..................# ... |
| correct output |
|---|
| 9 |
| user output |
|---|
| 9 |
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: ACCEPTED
| input |
|---|
| 1000 1000 ##############################... |
| correct output |
|---|
| 335 |
| user output |
|---|
| 335 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 20 20 #################### #####.############## ###.....############ ##.......########### ... |
| correct output |
|---|
| 10 |
| user output |
|---|
| 10 |
Test 8
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ##############################... |
| correct output |
|---|
| 436 |
| user output |
|---|
| 436 |
Test 9
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ##############################... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 10
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 20 20 #################### #B................## #################.## #################.## ... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 11
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 ##############################... |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
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 |
