#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int N = 4005;
int vis[N][N],cnt,n,m,ans;
string s[N];
queue<pair<int,int>> q,tmp;
void dfs(int x,int y,char c){
if(x > n || y > m || y < 0 || x < 0) return;
if(vis[x][y]) return;
if(!vis[x][y] && s[x][y] != c){
tmp.push({x,y});
return;
}
if(!vis[x][y]){
vis[x][y] = 1;
cnt++;
}
dfs(x+1,y,c);
dfs(x,y+1,c);
dfs(x,y-1,c);
dfs(x-1,y,c);
}
void solve(){
cin >> n >> m;
for(int i=0;i<n;i++)
cin >> s[i];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s[i][j] == '.'){
vis[i][j] = 1;
cnt++;
}
}
}
char c = s[n-1][m-1];
q.push({n-1,m-1});
while(cnt != n*m){
while(q.size()){
auto tp = q.front();
dfs(tp.ff,tp.ss,c);
q.pop();
}
while(tmp.size()){
q.push(tmp.front());
tmp.pop();
}
if(c == 'F') c = 'R';
else c = 'F';
ans++;
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
for(int i=1;i<=t;i++){
solve();
}
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:81:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen("in.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
tracks.cpp:82:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen("out.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
22 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
24 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
25 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
528 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |