#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pb push_back
#define mp make_pair
#define sz size
#define ll long long int
#define pi pair <int,int>
#define itn int
#define fr first
#define sc second
#define srt(v) sort(v.begin(), v.end())
#define rvs(v) reverse(v.begin(), v.end())
#define mod 1000000007
#define N 4010
using namespace std;
int h, w;
char m[N][N];
int f, r;
int mark[N][N];
void ff(int a, int b, bool isf){
if(mark[a][b] != -1) return;
mark[a][b] = 1;
if(isf){
m[a][b] = 'R';
f--;
if(m[a-1][b] == 'F') ff(a-1, b, true);
if(m[a][b-1] == 'F') ff(a, b-1, true);
if(m[a+1][b] == 'F') ff(a+1, b, true);
if(m[a][b+1] == 'F') ff(a, b+1, true);
}
else{
m[a][b] = 'F';
r--;
if(m[a-1][b] == 'R') ff(a-1, b, false);
if(m[a][b-1] == 'R') ff(a, b-1, false);
if(m[a+1][b] == 'R') ff(a+1, b, false);
if(m[a][b+1] == 'R') ff(a, b+1, false);
}
return;
}
main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> h >> w;
for(int i = 1;i <= h;i++){
for(int j = 1;j <= w;j++){
cin >> m[i][j];
if(m[i][j] == 'F') f++;
if(m[i][j] == 'R') r++;
}
}
int res = 0;
while(f != 0 and r != 0){
res++;
ms(mark);
if(m[1][1] == 'F')ff(1, 1, true);
else ff(1, 1, false);
}
cout << ++res << "\n";
return 0;
}
Compilation message
tracks.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2079 ms |
138288 KB |
Time limit exceeded |
2 |
Incorrect |
87 ms |
126236 KB |
Output isn't correct |
3 |
Execution timed out |
2086 ms |
126328 KB |
Time limit exceeded |
4 |
Execution timed out |
2094 ms |
135372 KB |
Time limit exceeded |
5 |
Execution timed out |
2095 ms |
127880 KB |
Time limit exceeded |
6 |
Incorrect |
88 ms |
126260 KB |
Output isn't correct |
7 |
Execution timed out |
2091 ms |
126416 KB |
Time limit exceeded |
8 |
Execution timed out |
2086 ms |
126556 KB |
Time limit exceeded |
9 |
Execution timed out |
2092 ms |
126560 KB |
Time limit exceeded |
10 |
Execution timed out |
2087 ms |
127692 KB |
Time limit exceeded |
11 |
Execution timed out |
2093 ms |
128824 KB |
Time limit exceeded |
12 |
Execution timed out |
2069 ms |
130700 KB |
Time limit exceeded |
13 |
Execution timed out |
2091 ms |
127824 KB |
Time limit exceeded |
14 |
Execution timed out |
2096 ms |
127692 KB |
Time limit exceeded |
15 |
Execution timed out |
2091 ms |
132096 KB |
Time limit exceeded |
16 |
Execution timed out |
2087 ms |
138284 KB |
Time limit exceeded |
17 |
Execution timed out |
2090 ms |
131064 KB |
Time limit exceeded |
18 |
Execution timed out |
2082 ms |
135372 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2090 ms |
141412 KB |
Time limit exceeded |
2 |
Execution timed out |
2085 ms |
138588 KB |
Time limit exceeded |
3 |
Execution timed out |
2048 ms |
157716 KB |
Time limit exceeded |
4 |
Execution timed out |
2074 ms |
141984 KB |
Time limit exceeded |
5 |
Execution timed out |
2059 ms |
146768 KB |
Time limit exceeded |
6 |
Execution timed out |
2117 ms |
875188 KB |
Time limit exceeded |
7 |
Execution timed out |
2085 ms |
141976 KB |
Time limit exceeded |
8 |
Execution timed out |
2090 ms |
141464 KB |
Time limit exceeded |
9 |
Execution timed out |
2076 ms |
127060 KB |
Time limit exceeded |
10 |
Execution timed out |
2082 ms |
126256 KB |
Time limit exceeded |
11 |
Execution timed out |
2081 ms |
141796 KB |
Time limit exceeded |
12 |
Execution timed out |
2096 ms |
126920 KB |
Time limit exceeded |
13 |
Execution timed out |
2089 ms |
138464 KB |
Time limit exceeded |
14 |
Execution timed out |
2079 ms |
134220 KB |
Time limit exceeded |
15 |
Execution timed out |
2093 ms |
131024 KB |
Time limit exceeded |
16 |
Execution timed out |
2096 ms |
132676 KB |
Time limit exceeded |
17 |
Execution timed out |
2080 ms |
146348 KB |
Time limit exceeded |
18 |
Execution timed out |
2081 ms |
137980 KB |
Time limit exceeded |
19 |
Execution timed out |
2080 ms |
142044 KB |
Time limit exceeded |
20 |
Execution timed out |
2080 ms |
136416 KB |
Time limit exceeded |
21 |
Execution timed out |
2029 ms |
147580 KB |
Time limit exceeded |
22 |
Execution timed out |
2020 ms |
146768 KB |
Time limit exceeded |
23 |
Execution timed out |
2091 ms |
154448 KB |
Time limit exceeded |
24 |
Execution timed out |
2074 ms |
147324 KB |
Time limit exceeded |
25 |
Execution timed out |
2065 ms |
157796 KB |
Time limit exceeded |
26 |
Correct |
170 ms |
26188 KB |
Output is correct |
27 |
Execution timed out |
2117 ms |
908480 KB |
Time limit exceeded |
28 |
Execution timed out |
2099 ms |
875212 KB |
Time limit exceeded |
29 |
Execution timed out |
2095 ms |
885552 KB |
Time limit exceeded |
30 |
Execution timed out |
2094 ms |
889792 KB |
Time limit exceeded |
31 |
Execution timed out |
2087 ms |
293128 KB |
Time limit exceeded |
32 |
Execution timed out |
2099 ms |
676624 KB |
Time limit exceeded |