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>
using namespace std;
int n, m;
vector<vector<char>> karte;
vector<vector<bool>> visited;
void floodfill(int x, int y, char tier){
karte[x][y] = '#';
visited[x][y] = true;
if(x+1<n && (karte[x+1][y]==tier || karte[x+1][y]=='#') && !visited[x+1][y]) floodfill(x+1, y, tier);
if(x-1>=0 && (karte[x-1][y]==tier || karte[x-1][y]=='#') && !visited[x-1][y]) floodfill(x-1, y, tier);
if(y+1<m && (karte[x][y+1]==tier || karte[x][y+1]=='#') && !visited[x][y+1]) floodfill(x, y+1, tier);
if(y-1>=0 && (karte[x][y-1]==tier || karte[x][y-1]=='#') && !visited[x][y-1]) floodfill(x, y-1, tier);
}
int main()
{
cin >> n >> m;
karte = vector<vector<char>>(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> karte[i][j];
}
}
/*for(vector<char> ele: karte) {
for(char x: ele){
cout << x;
}
cout << endl;
}
*/
int erg = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (karte[i][j] == 'F' || karte[i][j] == 'R') {
erg++;
visited = vector<vector<bool>>(n, vector<bool>(m, false));
floodfill(i, j, karte[i][j]);
}
}
}
cout << erg;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |