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;
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... |