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 h, w;
char m[4000][4000];
queue<pair<int, int> > q;
int vis[4000][4000];
vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
cin>>h>>w;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
cin>>m[h][w];
}
}
int res = 1;
char animal = m[0][0];
bool finish = false;
while(!finish) {
q.push({0, 0});
while(q.size()) {
int y = q.front().first;
int x = q.front().second;
q.pop();
finish = true;
if(vis[y][x] == res || animal != m[y][x])
continue;
vis[y][x] = res;
m[y][x] = 'A';
for(auto d : dir) {
int newY = y + d.first;
int newX = x + d.second;
if(newY >= 0 && newY < h && newX >= 0 && newX < w && vis[newY][newX] != res)
if(m[y][x] == animal || m[y][x] == 'A')
q.push({newY, newX});
}
}
res++;
if(animal == 'R')
animal = 'F';
else
animal = 'R';
}
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |