이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int R, C, M;
bitset<502> W[502] = {};
bitset<502> pos[2][502] = {};
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[1][i][j] = W[i][j];
}
cin >> I;
for(int k = 0; k < M; k++)
for(int i = 1; i <= R; i++) {
switch(I[k]) {
case 'N':
pos[k % 2][i] = pos[(k % 2) ^ 1][i+1] & W[i];
break;
case 'S':
pos[k % 2][i] = pos[(k % 2) ^ 1][i-1] & W[i];
break;
case 'E':
pos[k % 2][i] = pos[(k % 2) ^ 1][i] << 1 & W[i];
break;
case 'W':
pos[k % 2][i] = pos[(k % 2) ^ 1][i] >> 1 & W[i];
break;
case '?':
pos[k % 2][i] = (
(pos[(k % 2) ^ 1][i] << 1)
| (pos[(k % 2) ^ 1][i] >> 1)
| pos[(k % 2) ^ 1][i-1]
| pos[(k % 2) ^ 1][i+1]) & W[i];
break;
}
}
int res = 0;
for(int i = 1; i <= R; i++) for(int j = 1; j <= C; j++) {
if(pos[(M % 2) ^ 1][i][j])
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... |