#include <bits/stdc++.h>
using namespace std;
int moves[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int main(){
int n, m;
cin >> n >> m;
char arr[n][m];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> arr[i][j];
}
}
int num[n][m];
memset(num, 0, sizeof(num));
num[0][0] = 1;
deque<pair<int, int>> q;
q.push_back({0, 0});
int ans = 0;
while(!q.empty()){
pair<int, int> x = q.front();
q.pop_front();
ans = max(num[x.first][x.second], ans);
for(int i = 0; i < 4; i++){
int x1 = x.first + moves[i][0], y1 = x.second + moves[i][1];
if(x1 < 0 || y1 < 0 || x1 >= n || y1 >= m || num[x1][y1] != 0 || arr[x1][y1] == '.') continue;
if(arr[x1][y1] != arr[x.first][x.second]){
num[x1][y1] = num[x.first][x.second] + 1;
q.push_back({x1, y1});
} else {
num[x1][y1] = num[x.first][x.second];
q.push_back({x1, y1});
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
1516 KB |
Output isn't correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
14 ms |
1004 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
748 KB |
Output isn't correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
620 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
492 KB |
Output isn't correct |
12 |
Incorrect |
10 ms |
748 KB |
Output isn't correct |
13 |
Incorrect |
7 ms |
748 KB |
Output isn't correct |
14 |
Incorrect |
7 ms |
748 KB |
Output isn't correct |
15 |
Incorrect |
22 ms |
1516 KB |
Output isn't correct |
16 |
Incorrect |
22 ms |
1516 KB |
Output isn't correct |
17 |
Incorrect |
20 ms |
1516 KB |
Output isn't correct |
18 |
Incorrect |
14 ms |
1004 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
492 KB |
Output is correct |
2 |
Incorrect |
124 ms |
8044 KB |
Output isn't correct |
3 |
Incorrect |
1091 ms |
78536 KB |
Output isn't correct |
4 |
Incorrect |
270 ms |
18668 KB |
Output isn't correct |
5 |
Correct |
670 ms |
44396 KB |
Output is correct |
6 |
Incorrect |
1905 ms |
78828 KB |
Output isn't correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
492 KB |
Output is correct |
9 |
Incorrect |
5 ms |
620 KB |
Output isn't correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Incorrect |
4 ms |
492 KB |
Output isn't correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Incorrect |
136 ms |
8044 KB |
Output isn't correct |
14 |
Incorrect |
70 ms |
4716 KB |
Output isn't correct |
15 |
Correct |
72 ms |
5228 KB |
Output is correct |
16 |
Incorrect |
52 ms |
3436 KB |
Output isn't correct |
17 |
Incorrect |
340 ms |
20204 KB |
Output isn't correct |
18 |
Correct |
301 ms |
19820 KB |
Output is correct |
19 |
Incorrect |
272 ms |
18668 KB |
Output isn't correct |
20 |
Incorrect |
238 ms |
17260 KB |
Output isn't correct |
21 |
Incorrect |
647 ms |
45924 KB |
Output isn't correct |
22 |
Correct |
653 ms |
44396 KB |
Output is correct |
23 |
Incorrect |
687 ms |
38380 KB |
Output isn't correct |
24 |
Correct |
655 ms |
45048 KB |
Output is correct |
25 |
Correct |
1339 ms |
78572 KB |
Output is correct |
26 |
Correct |
1456 ms |
60656 KB |
Output is correct |
27 |
Incorrect |
1904 ms |
78716 KB |
Output isn't correct |
28 |
Incorrect |
1907 ms |
78700 KB |
Output isn't correct |
29 |
Incorrect |
1930 ms |
78764 KB |
Output isn't correct |
30 |
Incorrect |
1873 ms |
77036 KB |
Output isn't correct |
31 |
Incorrect |
1202 ms |
50540 KB |
Output isn't correct |
32 |
Incorrect |
1771 ms |
78788 KB |
Output isn't correct |