This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int H, W;
char grid[4000][4000];
bool visited[4000][4000];
void ff(int r, int c, char col){
if(r<0 || r>=H || c<0 || c>=W || visited[r][c] || grid[r][c]!=col) return;
visited[r][c] = true;
ff(r+1, c, col);
ff(r, c+1, col);
ff(r-1, c, col);
ff(r, c-1, col);
}
int main() {
//# of F connected componetntes + 1 or # of R compoentns + 1
cin >> H >> W;
for (int r=0; r<H; r++){
for (int c=0; c<W; c++){
cin >> grid[r][c];
}
}
vector<int> ccs;
ccs.push_back(0);
ccs.push_back(0);
for (int r=0; r<H; r++){
for (int c=0; c<W; c++){
if(!visited[r][c] && grid[r][c]!='.'){
ff(r, c, grid[r][c]);
if(grid[r][c]=='R') ccs[0]++;
else ccs[1]++;
}
}
}
cout << min(ccs[0], ccs[1])+1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |