#include <bits/stdc++.h>
using namespace std;
const int MXN = 505;
int r, c, m;
string A[MXN], moves;
bitset<MXN*MXN> water, poss, first_col, first_row, last_col, last_row;
int main() {
cin >> r >> c >> m;
for(int i = 0; i < r; i++) {
cin >> A[i];
for(int j = 0; j < c; j++) {
if(A[i][j] == '.') water[i*c+j] = 1;
}
}
for(int i = 0; i < r; i++) {
first_col[i*c] = 1;
last_col[i*c+c-1] = 1;
}
for(int i = 0; i < c; i++) {
first_row[i] = 1;
last_row[(r-1)*c+i] = 1;
}
poss = water;
cin >> moves;
for(int i = 0; i < m; i++) {
switch(moves[i]) {
case 'N':
poss = ((poss & ~first_row) >> c) & water;
break;
case 'E':
poss = ((poss & ~last_col) << 1) & water;
break;
case 'S':
poss = ((poss & ~last_row) << c) & water;
break;
case 'W':
poss = ((poss & ~first_col) >> 1) & water;
break;
case '?':
poss =
(((poss & ~first_row) >> c) |
((poss & ~last_col) << 1) |
((poss & ~last_row) << c) |
((poss & ~first_col) >> 1))
& water;
break;
default:
assert(false);
}
}
cout << poss.count() << "\n";
return 0;
}
/*
3 3 1
...
.#.
...
E
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
828 KB |
Output is correct |
2 |
Correct |
3 ms |
828 KB |
Output is correct |
3 |
Correct |
3 ms |
816 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
828 KB |
Output is correct |
2 |
Correct |
3 ms |
828 KB |
Output is correct |
3 |
Correct |
3 ms |
816 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
828 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
828 KB |
Output is correct |
9 |
Correct |
7 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
824 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
6 ms |
852 KB |
Output is correct |
13 |
Correct |
7 ms |
852 KB |
Output is correct |
14 |
Correct |
7 ms |
852 KB |
Output is correct |
15 |
Correct |
6 ms |
852 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
7 ms |
852 KB |
Output is correct |
18 |
Correct |
8 ms |
852 KB |
Output is correct |
19 |
Correct |
7 ms |
852 KB |
Output is correct |
20 |
Correct |
8 ms |
892 KB |
Output is correct |
21 |
Correct |
8 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
828 KB |
Output is correct |
2 |
Correct |
3 ms |
828 KB |
Output is correct |
3 |
Correct |
3 ms |
816 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
828 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
828 KB |
Output is correct |
9 |
Correct |
7 ms |
852 KB |
Output is correct |
10 |
Correct |
5 ms |
824 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
6 ms |
852 KB |
Output is correct |
13 |
Correct |
7 ms |
852 KB |
Output is correct |
14 |
Correct |
7 ms |
852 KB |
Output is correct |
15 |
Correct |
6 ms |
852 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
7 ms |
852 KB |
Output is correct |
18 |
Correct |
8 ms |
852 KB |
Output is correct |
19 |
Correct |
7 ms |
852 KB |
Output is correct |
20 |
Correct |
8 ms |
892 KB |
Output is correct |
21 |
Correct |
8 ms |
828 KB |
Output is correct |
22 |
Correct |
163 ms |
1676 KB |
Output is correct |
23 |
Correct |
153 ms |
1676 KB |
Output is correct |
24 |
Correct |
169 ms |
1684 KB |
Output is correct |
25 |
Correct |
155 ms |
1676 KB |
Output is correct |
26 |
Correct |
152 ms |
1620 KB |
Output is correct |
27 |
Correct |
255 ms |
1676 KB |
Output is correct |
28 |
Correct |
260 ms |
1620 KB |
Output is correct |
29 |
Correct |
239 ms |
1672 KB |
Output is correct |
30 |
Correct |
304 ms |
1772 KB |
Output is correct |
31 |
Correct |
242 ms |
1644 KB |
Output is correct |
32 |
Correct |
326 ms |
1672 KB |
Output is correct |
33 |
Correct |
301 ms |
1672 KB |
Output is correct |
34 |
Correct |
326 ms |
1668 KB |
Output is correct |
35 |
Correct |
334 ms |
1672 KB |
Output is correct |
36 |
Correct |
320 ms |
1652 KB |
Output is correct |