This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
tracks.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |