#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 501
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int n, m, depth[MAXN][MAXN], ans = 1;
char snow[MAXN][MAXN];
bool inside(int x, int y) {
return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>snow[i][j];
}
}
memset(depth,0,sizeof(depth));
deque<pair<int,int>>dq;
dq.push_back({0,0});
depth[0][0]=1;
while(!dq.empty()){
auto curr = dq.front();
int r = curr.first, c = curr.second;
dq.pop_front();
ans = max(ans,depth[r][c]);
for(int i=0;i<4;i++){
int nr = r+dx[i], nc = c+dy[i];
if(inside(nr,nc)&&depth[nr][nc]==0){
if(snow[r][c]==snow[nr][nc]){
depth[nr][nc] = depth[r][c];
dq.push_front({nr,nc});
}
else{
depth[nr][nc] = depth[r][c]+1;
dq.push_back({nr,nc});
}
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
3008 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
3 ms |
2648 KB |
Output is correct |
15 |
Correct |
9 ms |
2908 KB |
Output is correct |
16 |
Correct |
9 ms |
2908 KB |
Output is correct |
17 |
Correct |
7 ms |
2908 KB |
Output is correct |
18 |
Correct |
5 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Incorrect |
16 ms |
4188 KB |
Output isn't correct |
3 |
Incorrect |
137 ms |
18116 KB |
Output isn't correct |
4 |
Runtime error |
37 ms |
8532 KB |
Execution killed with signal 11 |
5 |
Incorrect |
82 ms |
11328 KB |
Output isn't correct |
6 |
Runtime error |
162 ms |
21976 KB |
Execution killed with signal 11 |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2724 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
2592 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
2432 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Incorrect |
17 ms |
4184 KB |
Output isn't correct |
14 |
Incorrect |
11 ms |
3420 KB |
Output isn't correct |
15 |
Incorrect |
10 ms |
3544 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
3164 KB |
Output isn't correct |
17 |
Incorrect |
39 ms |
6488 KB |
Output isn't correct |
18 |
Incorrect |
36 ms |
6480 KB |
Output isn't correct |
19 |
Runtime error |
36 ms |
8528 KB |
Execution killed with signal 11 |
20 |
Incorrect |
31 ms |
5968 KB |
Output isn't correct |
21 |
Incorrect |
93 ms |
11728 KB |
Output isn't correct |
22 |
Incorrect |
75 ms |
11348 KB |
Output isn't correct |
23 |
Incorrect |
68 ms |
10040 KB |
Output isn't correct |
24 |
Incorrect |
78 ms |
11348 KB |
Output isn't correct |
25 |
Incorrect |
139 ms |
18252 KB |
Output isn't correct |
26 |
Runtime error |
112 ms |
21064 KB |
Execution killed with signal 11 |
27 |
Runtime error |
146 ms |
24004 KB |
Execution killed with signal 11 |
28 |
Runtime error |
148 ms |
22096 KB |
Execution killed with signal 11 |
29 |
Runtime error |
147 ms |
21716 KB |
Execution killed with signal 11 |
30 |
Runtime error |
191 ms |
21960 KB |
Execution killed with signal 11 |
31 |
Runtime error |
105 ms |
15096 KB |
Execution killed with signal 11 |
32 |
Runtime error |
144 ms |
22092 KB |
Execution killed with signal 11 |