This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |