이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[i][j];
}
}
int res = 1;
char animal = m[0][0];
bool finish = false;
while(!finish) {
q.push({0, 0});
finish = true;
while(q.size()) {
int y = q.front().first;
int x = q.front().second;
q.pop();
if(vis[y][x] == res || (animal != m[y][x] && m[y][x] != 'A'))
continue;
if(m[y][x] != 'A')
finish = false;
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[newY][newX] == animal || m[newY][newX] == 'A')
q.push({newY, newX});
}
}
res++;
if(animal == 'R')
animal = 'F';
else
animal = 'R';
}
cout<<res - 2<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |