#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 0
#else
#include "C:\programmingfunnyxd\debug.cpp"
#endif
using namespace std;
#define int long long
int n,m;
char grid[4000][4000];
bool fvisited[4000][4000], svisited[4000][4000];
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,-1,1};
char first, second;
void firstfill(int r, int c){
if(r < 0 || r >= n || c < 0 || c >= m)return;
if(fvisited[r][c] || grid[r][c] != first)return;
fvisited[r][c] = true;
for(int i = 0; i < n; i++){
firstfill(dx[i]+r, dy[i]+c);
}
}
void secondfill(int r, int c){
if(r < 0 || r >= n || c < 0 || c >= m)return;
if(svisited[r][c])return;
if(!fvisited[r][c] && grid[r][c] != second)return;
svisited[r][c] = true;
for(int i = 0; i < n; i++){
secondfill(dx[i]+r, dy[i]+c);
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin>>grid[i][j];
}
}
first = grid[0][0];
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j] == first && !fvisited[i][j]){
ans++;
firstfill(i,j);
}
}
}
second = (first == 'F' ? 'R' : 'F');
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j] == second and !svisited[i][j]){
ans++;
secondfill(i,j);
}
}
}
cout<<ans;
}
Compilation message
tracks.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
708 ms |
15868 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
832 KB |
Output isn't correct |
4 |
Incorrect |
462 ms |
13296 KB |
Output isn't correct |
5 |
Incorrect |
41 ms |
4160 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
844 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1228 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
1484 KB |
Output isn't correct |
10 |
Incorrect |
48 ms |
3452 KB |
Output isn't correct |
11 |
Incorrect |
57 ms |
4572 KB |
Output isn't correct |
12 |
Incorrect |
172 ms |
6808 KB |
Output isn't correct |
13 |
Incorrect |
43 ms |
4164 KB |
Output isn't correct |
14 |
Incorrect |
42 ms |
4224 KB |
Output isn't correct |
15 |
Incorrect |
566 ms |
7876 KB |
Output isn't correct |
16 |
Incorrect |
711 ms |
15836 KB |
Output isn't correct |
17 |
Incorrect |
321 ms |
8316 KB |
Output isn't correct |
18 |
Incorrect |
471 ms |
13372 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
376 ms |
45860 KB |
Output isn't correct |
2 |
Execution timed out |
2075 ms |
13564 KB |
Time limit exceeded |
3 |
Execution timed out |
2066 ms |
47536 KB |
Time limit exceeded |
4 |
Execution timed out |
2074 ms |
19024 KB |
Time limit exceeded |
5 |
Execution timed out |
2076 ms |
32768 KB |
Time limit exceeded |
6 |
Execution timed out |
2071 ms |
41140 KB |
Time limit exceeded |
7 |
Incorrect |
358 ms |
47896 KB |
Output isn't correct |
8 |
Incorrect |
368 ms |
45804 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
1228 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
11 |
Incorrect |
241 ms |
46744 KB |
Output isn't correct |
12 |
Incorrect |
13 ms |
2628 KB |
Output isn't correct |
13 |
Execution timed out |
2081 ms |
13764 KB |
Time limit exceeded |
14 |
Execution timed out |
2089 ms |
14688 KB |
Time limit exceeded |
15 |
Incorrect |
1831 ms |
25932 KB |
Output isn't correct |
16 |
Incorrect |
883 ms |
7984 KB |
Output isn't correct |
17 |
Execution timed out |
2087 ms |
17228 KB |
Time limit exceeded |
18 |
Execution timed out |
2085 ms |
19932 KB |
Time limit exceeded |
19 |
Execution timed out |
2082 ms |
18864 KB |
Time limit exceeded |
20 |
Execution timed out |
2084 ms |
17468 KB |
Time limit exceeded |
21 |
Execution timed out |
2087 ms |
33860 KB |
Time limit exceeded |
22 |
Execution timed out |
2086 ms |
32836 KB |
Time limit exceeded |
23 |
Execution timed out |
2077 ms |
22336 KB |
Time limit exceeded |
24 |
Execution timed out |
2085 ms |
33864 KB |
Time limit exceeded |
25 |
Execution timed out |
2090 ms |
47488 KB |
Time limit exceeded |
26 |
Execution timed out |
2106 ms |
614976 KB |
Time limit exceeded |
27 |
Execution timed out |
2073 ms |
111764 KB |
Time limit exceeded |
28 |
Execution timed out |
2074 ms |
41312 KB |
Time limit exceeded |
29 |
Execution timed out |
2073 ms |
42140 KB |
Time limit exceeded |
30 |
Execution timed out |
2073 ms |
41364 KB |
Time limit exceeded |
31 |
Execution timed out |
2091 ms |
25976 KB |
Time limit exceeded |
32 |
Execution timed out |
2062 ms |
47332 KB |
Time limit exceeded |