제출 #518764

#제출 시각아이디문제언어결과실행 시간메모리
518764neonahtTracks in the Snow (BOI13_tracks)C++14
100 / 100
1495 ms46796 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...