#include <bits/stdc++.h>
using namespace std;
int h, w;
char m[4000][4000];
queue<pair<int, int> > q;
int vis[4000][4000];
vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
cin>>h>>w;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
cin>>m[h][w];
}
}
int res = 1;
char animal = m[0][0];
bool finish = false;
while(!finish) {
q.push({0, 0});
while(q.size()) {
int y = q.front().first;
int x = q.front().second;
q.pop();
finish = true;
if(vis[y][x] == res || animal != m[y][x])
continue;
vis[y][x] = res;
m[y][x] = 'A';
for(auto d : dir) {
int newY = y + d.first;
int newX = x + d.second;
if(newY >= 0 && newY < h && newX >= 0 && newX < w && vis[newY][newX] != res)
if(m[y][x] == animal || m[y][x] == 'A')
q.push({newY, newX});
}
}
res++;
if(animal == 'R')
animal = 'F';
else
animal = 'R';
}
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
7256 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
4 |
Incorrect |
9 ms |
7004 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
3932 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2904 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
3676 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
3416 KB |
Output isn't correct |
12 |
Incorrect |
7 ms |
3928 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
3736 KB |
Output isn't correct |
14 |
Incorrect |
7 ms |
3928 KB |
Output isn't correct |
15 |
Incorrect |
13 ms |
7368 KB |
Output isn't correct |
16 |
Incorrect |
13 ms |
7360 KB |
Output isn't correct |
17 |
Incorrect |
12 ms |
7260 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
7004 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
32604 KB |
Output isn't correct |
2 |
Incorrect |
86 ms |
17516 KB |
Output isn't correct |
3 |
Incorrect |
792 ms |
78756 KB |
Output isn't correct |
4 |
Incorrect |
195 ms |
32852 KB |
Output isn't correct |
5 |
Incorrect |
452 ms |
61776 KB |
Output isn't correct |
6 |
Incorrect |
785 ms |
78672 KB |
Output isn't correct |
7 |
Incorrect |
13 ms |
33116 KB |
Output isn't correct |
8 |
Incorrect |
13 ms |
32632 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
2652 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
11 |
Incorrect |
13 ms |
32992 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
13 |
Incorrect |
80 ms |
17580 KB |
Output isn't correct |
14 |
Incorrect |
59 ms |
13904 KB |
Output isn't correct |
15 |
Incorrect |
60 ms |
14260 KB |
Output isn't correct |
16 |
Incorrect |
31 ms |
8536 KB |
Output isn't correct |
17 |
Incorrect |
200 ms |
34472 KB |
Output isn't correct |
18 |
Incorrect |
217 ms |
34644 KB |
Output isn't correct |
19 |
Incorrect |
198 ms |
32852 KB |
Output isn't correct |
20 |
Incorrect |
170 ms |
29012 KB |
Output isn't correct |
21 |
Incorrect |
453 ms |
63156 KB |
Output isn't correct |
22 |
Incorrect |
458 ms |
61608 KB |
Output isn't correct |
23 |
Incorrect |
402 ms |
51792 KB |
Output isn't correct |
24 |
Incorrect |
456 ms |
62800 KB |
Output isn't correct |
25 |
Incorrect |
838 ms |
78512 KB |
Output isn't correct |
26 |
Incorrect |
598 ms |
71508 KB |
Output isn't correct |
27 |
Incorrect |
837 ms |
78764 KB |
Output isn't correct |
28 |
Incorrect |
822 ms |
78756 KB |
Output isn't correct |
29 |
Incorrect |
772 ms |
78692 KB |
Output isn't correct |
30 |
Incorrect |
803 ms |
78160 KB |
Output isn't correct |
31 |
Incorrect |
513 ms |
64848 KB |
Output isn't correct |
32 |
Incorrect |
814 ms |
78520 KB |
Output isn't correct |