이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int R, C, M;
bool W[502][502] = {};
bool pos[502][502][2] = {};
queue<ii> pts;
string I;
int main() {
cin >> R >> C >> M;
char c;
for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) {
cin >> c;
W[i][j] = c == '.';
pos[i][j][1] = W[i][j];
}
cin >> I;
for(int k = 0; k < M; k++)
for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) if(W[i][j]) {
switch(I[k]) {
case 'N':
pos[i][j][k % 2] = pos[i+1][j][(k % 2) ^ 1];
break;
case 'S':
pos[i][j][k % 2] = pos[i-1][j][(k % 2) ^ 1];
break;
case 'E':
pos[i][j][k % 2] = pos[i][j-1][(k % 2) ^ 1];
break;
case 'W':
pos[i][j][k % 2] = pos[i][j+1][(k % 2) ^ 1];
break;
case '?':
pos[i][j][k % 2]
= pos[i][j-1][(k % 2) ^ 1]
| pos[i][j+1][(k % 2) ^ 1]
| pos[i-1][j][(k % 2) ^ 1]
| pos[i+1][j][(k % 2) ^ 1];
break;
}
}
int res = 0;
for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) {
if(pos[i][j][(M % 2) ^ 1])
res++;
}
cout << res << endl;
return 0;
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |