#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxH=505, mxW=505;
int H, W;
char grid[mxH][mxW], rChange[4]={0, 1, 0, -1}, cChange[4]={1, 0, -1, 0};
bool vis[mxH][mxW];
int floodfill(int r, int c, char curr) {
int cnt=0;
stack<pair<int, int>> frontier;
frontier.push({r, c});
while(!frontier.empty()) {
r=frontier.top().first;
c=frontier.top().second;
frontier.pop();
if(r<0||r>=H||c<0||c>=W||grid[r][c]!=curr||vis[r][c]) {
continue;
}
++cnt;
vis[r][c]=1;
grid[r][c]=(grid[r][c]=='F'?'R' : 'F');
for(int i=0; i<4; ++i)
frontier.push({r+rChange[i], c+cChange[i]});
}
return cnt;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> H >> W;
int tot=0;
for(int i=0; i<H; ++i) {
for(int j=0; j<W; ++j) {
cin >> grid[i][j];
if(grid[i][j]!='.')
++tot;
}
}
int ans=0;
while(1) {
memset(vis, 0, sizeof(vis));
if(tot==floodfill(0, 0, grid[0][0]))
break;
++ans;
}
cout << ans+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
4532 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
596 KB |
Output is correct |
4 |
Correct |
32 ms |
3388 KB |
Output is correct |
5 |
Correct |
66 ms |
908 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
107 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
1376 KB |
Output is correct |
12 |
Correct |
95 ms |
1900 KB |
Output is correct |
13 |
Correct |
66 ms |
932 KB |
Output is correct |
14 |
Correct |
66 ms |
940 KB |
Output is correct |
15 |
Correct |
774 ms |
2400 KB |
Output is correct |
16 |
Correct |
315 ms |
4532 KB |
Output is correct |
17 |
Correct |
487 ms |
2004 KB |
Output is correct |
18 |
Correct |
32 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
2 |
Runtime error |
7 ms |
1856 KB |
Execution killed with signal 11 |
3 |
Runtime error |
19 ms |
1900 KB |
Execution killed with signal 11 |
4 |
Runtime error |
10 ms |
2016 KB |
Execution killed with signal 11 |
5 |
Runtime error |
14 ms |
2564 KB |
Execution killed with signal 11 |
6 |
Runtime error |
20 ms |
2392 KB |
Execution killed with signal 11 |
7 |
Runtime error |
2 ms |
984 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
988 KB |
Execution killed with signal 11 |
9 |
Execution timed out |
2063 ms |
596 KB |
Time limit exceeded |
10 |
Execution timed out |
2079 ms |
596 KB |
Time limit exceeded |
11 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
12 |
Execution timed out |
2076 ms |
860 KB |
Time limit exceeded |
13 |
Runtime error |
7 ms |
1748 KB |
Execution killed with signal 11 |
14 |
Runtime error |
5 ms |
1620 KB |
Execution killed with signal 11 |
15 |
Runtime error |
6 ms |
1628 KB |
Execution killed with signal 11 |
16 |
Execution timed out |
2060 ms |
1436 KB |
Time limit exceeded |
17 |
Runtime error |
10 ms |
2004 KB |
Execution killed with signal 11 |
18 |
Runtime error |
10 ms |
2000 KB |
Execution killed with signal 11 |
19 |
Runtime error |
11 ms |
2004 KB |
Execution killed with signal 11 |
20 |
Runtime error |
10 ms |
2012 KB |
Execution killed with signal 11 |
21 |
Runtime error |
15 ms |
2624 KB |
Execution killed with signal 11 |
22 |
Runtime error |
15 ms |
2548 KB |
Execution killed with signal 11 |
23 |
Runtime error |
17 ms |
2740 KB |
Execution killed with signal 11 |
24 |
Runtime error |
17 ms |
2508 KB |
Execution killed with signal 11 |
25 |
Runtime error |
19 ms |
2380 KB |
Execution killed with signal 11 |
26 |
Runtime error |
17 ms |
2636 KB |
Execution killed with signal 11 |
27 |
Runtime error |
19 ms |
2708 KB |
Execution killed with signal 11 |
28 |
Runtime error |
19 ms |
2480 KB |
Execution killed with signal 11 |
29 |
Runtime error |
19 ms |
2476 KB |
Execution killed with signal 11 |
30 |
Runtime error |
24 ms |
2312 KB |
Execution killed with signal 11 |
31 |
Runtime error |
15 ms |
2644 KB |
Execution killed with signal 11 |
32 |
Runtime error |
19 ms |
1356 KB |
Execution killed with signal 11 |