이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int u[] = {0, 1, 0, -1};
const int v[] = {1 , 0, -1, 0};
const int N = 4055;
int W, H;
char snow[N][N];
bool safe(int u, int v)
{
return (u >= 0 && u < W && v >= 0 && v < H);
}
void solve()
{
cin >> W >> H;
for(int row=0; row<W; row++)
{
for(int col=0; col<H; col++)
{
cin >> snow[row][col];
}
}
queue<pair<int, int>> que[2];
int num = 0;
que[num & 1].push(make_pair(W - 1, H - 1));
char track = snow[W - 1][H - 1];
snow[W - 1][H - 1] = '#';
while(!que[num & 1].empty())
{
int rest = 1 - (num & 1);
int cur = num & 1;
while(!que[cur].empty())
{
pair<int, int> now = que[cur].front();
que[cur].pop();
int curU = now.fi, curV = now.se;
for(int i=0; i<4; i++)
{
int ux = curU + u[i], vx = curV + v[i];
if (safe(ux, vx))
{
if (snow[ux][vx] == track)
{
que[cur].push(make_pair(ux, vx));
snow[ux][vx] = '#';
} else
{
if (snow[ux][vx] != '.' && snow[ux][vx] != '#')
{
que[rest].push(make_pair(ux, vx));
snow[ux][vx] = '#';
}
}
}
}
}
track = (track == 'F' ? 'R' : 'F');
num++;
}
cout << num;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |