#include <bits/stdc++.h>
using namespace std;
char g[4005][4005];
bitset<4005> vis[4005];
vector<pair<short, short>> layer[4005];
int h, w, dep = 1;
const int dr[4] = {0, 1, 0, -1}, dc[4] = {1, 0, -1, 0};
void dfs (int r, int c, char ch) {
if (!vis[r][c]) layer[dep].push_back({r, c});
vis[r][c] = true;
for (int k = 0; k < 4; k++) {
int rv = r + dr[k], cv = c + dc[k];
if (rv >= 1 && rv <= h && cv >= 1 && cv <= w && !vis[rv][cv] && g[rv][cv] == ch) dfs(rv, cv, ch);
}
}
int main () {
cin >> h >> w;
for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> g[i][j];
dfs(1, 1, g[1][1]);
while (true) {
dep++;
for (auto& [r, c] : layer[dep-1]) dfs(r, c, "RF"[(dep & 1) ^ (g[1][1] == 'R')]);
layer[dep-1].clear();
if (layer[dep].empty()) {
cout << dep-1 << '\n';
return 0;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5724 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
11 ms |
6744 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
4892 KB |
Output is correct |
11 |
Correct |
3 ms |
5648 KB |
Output is correct |
12 |
Correct |
7 ms |
4956 KB |
Output is correct |
13 |
Correct |
4 ms |
4700 KB |
Output is correct |
14 |
Correct |
4 ms |
4700 KB |
Output is correct |
15 |
Correct |
17 ms |
5468 KB |
Output is correct |
16 |
Correct |
18 ms |
5724 KB |
Output is correct |
17 |
Correct |
14 ms |
5212 KB |
Output is correct |
18 |
Correct |
11 ms |
6940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
35932 KB |
Execution killed with signal 11 |
2 |
Correct |
74 ms |
12560 KB |
Output is correct |
3 |
Runtime error |
476 ms |
38404 KB |
Execution killed with signal 11 |
4 |
Correct |
129 ms |
14164 KB |
Output is correct |
5 |
Runtime error |
250 ms |
31316 KB |
Execution killed with signal 11 |
6 |
Correct |
1006 ms |
197068 KB |
Output is correct |
7 |
Runtime error |
16 ms |
37468 KB |
Execution killed with signal 11 |
8 |
Runtime error |
15 ms |
35972 KB |
Execution killed with signal 11 |
9 |
Correct |
3 ms |
2908 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
5 ms |
18268 KB |
Output is correct |
12 |
Runtime error |
4 ms |
9304 KB |
Execution killed with signal 11 |
13 |
Correct |
73 ms |
12556 KB |
Output is correct |
14 |
Correct |
42 ms |
8788 KB |
Output is correct |
15 |
Runtime error |
33 ms |
13908 KB |
Execution killed with signal 11 |
16 |
Correct |
37 ms |
6744 KB |
Output is correct |
17 |
Correct |
176 ms |
19280 KB |
Output is correct |
18 |
Runtime error |
114 ms |
22536 KB |
Execution killed with signal 11 |
19 |
Correct |
126 ms |
14160 KB |
Output is correct |
20 |
Runtime error |
106 ms |
22720 KB |
Execution killed with signal 11 |
21 |
Runtime error |
238 ms |
31488 KB |
Execution killed with signal 11 |
22 |
Runtime error |
229 ms |
31316 KB |
Execution killed with signal 11 |
23 |
Runtime error |
364 ms |
58896 KB |
Execution killed with signal 11 |
24 |
Runtime error |
238 ms |
31264 KB |
Execution killed with signal 11 |
25 |
Runtime error |
420 ms |
38536 KB |
Execution killed with signal 11 |
26 |
Runtime error |
872 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Correct |
1329 ms |
817740 KB |
Output is correct |
28 |
Correct |
1094 ms |
195808 KB |
Output is correct |
29 |
Correct |
1038 ms |
165316 KB |
Output is correct |
30 |
Correct |
1091 ms |
337172 KB |
Output is correct |
31 |
Correct |
759 ms |
58600 KB |
Output is correct |
32 |
Correct |
1256 ms |
588412 KB |
Output is correct |