이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int SZ=4004;
char an[SZ][SZ],usx[]={'R','F'};
int dx[]={-1,0,1,0},dy[]={0,1,0,-1},chx;
struct A {
int x,y,t;
};
int main() {
int w,h,res(0);
cin >> h >> w;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) cin >> an[i][j];
}
queue <A> hx[2];
hx[chx].push({0,0,(an[0][0]=='R' ? 0:1)});
an[0][0]='*';
while(!hx[chx].empty()) {
while(!hx[chx].empty()) {
auto o=hx[chx].front();
hx[chx].pop();
for(int i=0;i<4;i++) {
int xx=o.x+dx[i],yy=o.y+dy[i];
if(xx<0 || yy<0 || xx>h-1 || yy>w-1 || an[xx][yy]=='*') continue;
if(an[xx][yy]==usx[o.t]) hx[chx].push({xx,yy,o.t}),an[xx][yy]='*';
else if(an[xx][yy]==usx[1-o.t]) hx[1-chx].push({xx,yy,1-o.t}),an[xx][yy]='*';
}
}
++res;
chx=1-chx;
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |