#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {-1, 1, 0, 0},
dy = {0, 0, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w; cin >> h >> w;
vector<string> grid(h);
for (string& s : grid) cin >> s;
deque<pair<int, pair<int, int>>> dq;
dq.push_front({1, {0, 0}});
vector<vector<bool>> vis(h, vector<bool>(w));
int ans = 1;
while (!dq.empty()) {
int d = dq.front().first;
pair<int, int> pla = dq.front().second;
dq.pop_front();
if (vis[pla.first][pla.second]) continue;
vis[pla.first][pla.second] = true;
ans = max(ans, d);
for (int i = 0; i < 4; ++i) {
pair<int, int> ne = {pla.first + dx[i], pla.second + dy[i]};
if (ne.first < 0 || ne.first >= h || ne.second < 0 || ne.second >= w) continue;
if (grid[pla.first][pla.second] == grid[ne.first][ne.second]) {
dq.push_front({d, ne});
} else {
dq.push_back({d + 1, ne});
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1368 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Correct |
9 ms |
1260 KB |
Output is correct |
5 |
Incorrect |
5 ms |
1012 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
1116 KB |
Output isn't correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Incorrect |
5 ms |
860 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
860 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
1012 KB |
Output isn't correct |
15 |
Incorrect |
16 ms |
3672 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
1372 KB |
Output isn't correct |
17 |
Incorrect |
13 ms |
1372 KB |
Output isn't correct |
18 |
Correct |
10 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1448 KB |
Output isn't correct |
2 |
Incorrect |
94 ms |
22020 KB |
Output isn't correct |
3 |
Incorrect |
1111 ms |
341968 KB |
Output isn't correct |
4 |
Incorrect |
211 ms |
12372 KB |
Output isn't correct |
5 |
Incorrect |
458 ms |
240740 KB |
Output isn't correct |
6 |
Correct |
1072 ms |
88656 KB |
Output is correct |
7 |
Incorrect |
3 ms |
1368 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1372 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
876 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1880 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
13 |
Incorrect |
90 ms |
21792 KB |
Output isn't correct |
14 |
Incorrect |
52 ms |
12960 KB |
Output isn't correct |
15 |
Incorrect |
58 ms |
14300 KB |
Output isn't correct |
16 |
Incorrect |
37 ms |
10284 KB |
Output isn't correct |
17 |
Incorrect |
235 ms |
56372 KB |
Output isn't correct |
18 |
Incorrect |
248 ms |
58392 KB |
Output isn't correct |
19 |
Incorrect |
200 ms |
12372 KB |
Output isn't correct |
20 |
Incorrect |
225 ms |
72692 KB |
Output isn't correct |
21 |
Incorrect |
646 ms |
196524 KB |
Output isn't correct |
22 |
Incorrect |
406 ms |
242684 KB |
Output isn't correct |
23 |
Incorrect |
461 ms |
111036 KB |
Output isn't correct |
24 |
Incorrect |
523 ms |
135964 KB |
Output isn't correct |
25 |
Incorrect |
1157 ms |
241960 KB |
Output isn't correct |
26 |
Correct |
1030 ms |
400664 KB |
Output is correct |
27 |
Correct |
977 ms |
121852 KB |
Output is correct |
28 |
Correct |
1036 ms |
88612 KB |
Output is correct |
29 |
Correct |
1115 ms |
82044 KB |
Output is correct |
30 |
Correct |
989 ms |
106584 KB |
Output is correct |
31 |
Incorrect |
601 ms |
25308 KB |
Output isn't correct |
32 |
Incorrect |
1004 ms |
135296 KB |
Output isn't correct |