#include <bits/stdc++.h>
using namespace std;
int dx[4] {1,-1,0,0} ,dy[4]{0,0,1,-1};
int n,m,depth[4000][4000],ans=1;
string snow[1000];
bool istrace(int x,int y){
return x>-1 && x<n && y>-1 && y<m && snow[x][y]!='.';
}
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>snow[i];
deque<pair<int,int>>q;
q.push_back({0,0});
depth[0][0]=1;
while(q.size()){
pair<int,int>c=q.front();
q.pop_front();
ans=max(ans,depth[c.first][c.second]);
for(int i=0;i<4;i++){
int x=c.first+dx[i] ,y=c.second+dy[i];
if(istrace(x,y) && depth[x][y]==0){
if(snow[x][y]==snow[c.first][c.second]){
depth[x][y]=depth[c.first][c.second];
q.push_front({x,y});
}
else{
depth[x][y]=depth[c.first][c.second]+1;
q.push_back({x,y});
}
}
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3788 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
7 ms |
3304 KB |
Output is correct |
5 |
Correct |
3 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
4 ms |
1644 KB |
Output is correct |
11 |
Correct |
3 ms |
1356 KB |
Output is correct |
12 |
Correct |
5 ms |
1996 KB |
Output is correct |
13 |
Correct |
3 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
11 ms |
3660 KB |
Output is correct |
16 |
Correct |
13 ms |
3800 KB |
Output is correct |
17 |
Correct |
9 ms |
3584 KB |
Output is correct |
18 |
Correct |
7 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
588 KB |
Execution killed with signal 11 |
2 |
Runtime error |
8 ms |
4556 KB |
Execution killed with signal 11 |
3 |
Runtime error |
20 ms |
13568 KB |
Execution killed with signal 11 |
4 |
Runtime error |
11 ms |
6880 KB |
Execution killed with signal 11 |
5 |
Runtime error |
13 ms |
10288 KB |
Execution killed with signal 11 |
6 |
Runtime error |
17 ms |
13552 KB |
Execution killed with signal 11 |
7 |
Runtime error |
5 ms |
496 KB |
Execution killed with signal 11 |
8 |
Runtime error |
4 ms |
508 KB |
Execution killed with signal 11 |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Runtime error |
4 ms |
504 KB |
Execution killed with signal 11 |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Runtime error |
9 ms |
4556 KB |
Execution killed with signal 11 |
14 |
Correct |
33 ms |
7748 KB |
Output is correct |
15 |
Correct |
23 ms |
10188 KB |
Output is correct |
16 |
Correct |
21 ms |
4780 KB |
Output is correct |
17 |
Runtime error |
11 ms |
7012 KB |
Execution killed with signal 11 |
18 |
Runtime error |
11 ms |
6868 KB |
Execution killed with signal 11 |
19 |
Runtime error |
10 ms |
6860 KB |
Execution killed with signal 11 |
20 |
Runtime error |
10 ms |
6808 KB |
Execution killed with signal 11 |
21 |
Runtime error |
14 ms |
10288 KB |
Execution killed with signal 11 |
22 |
Runtime error |
15 ms |
10184 KB |
Execution killed with signal 11 |
23 |
Runtime error |
14 ms |
10512 KB |
Execution killed with signal 11 |
24 |
Runtime error |
15 ms |
9924 KB |
Execution killed with signal 11 |
25 |
Runtime error |
20 ms |
13708 KB |
Execution killed with signal 11 |
26 |
Runtime error |
15 ms |
11816 KB |
Execution killed with signal 11 |
27 |
Runtime error |
17 ms |
13556 KB |
Execution killed with signal 11 |
28 |
Runtime error |
17 ms |
13532 KB |
Execution killed with signal 11 |
29 |
Runtime error |
16 ms |
13612 KB |
Execution killed with signal 11 |
30 |
Runtime error |
19 ms |
13504 KB |
Execution killed with signal 11 |
31 |
Runtime error |
15 ms |
10856 KB |
Execution killed with signal 11 |
32 |
Runtime error |
18 ms |
13504 KB |
Execution killed with signal 11 |