#include <iostream>
#include <bitset>
using namespace std;
const int MAXN = 501;
const int SZ = MAXN * MAXN;
bitset<SZ> empty_cell;
bitset<SZ> move_west;
bitset<SZ> move_east;
bitset<SZ> move_south;
bitset<SZ> ans;
signed main() {
int r, c, m;
cin >> r >> c >> m;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
char ch;
cin >> ch;
empty_cell[i * c + j] = (ch == '.');
if (j)
move_west[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j - 1];
}
}
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
if (j + 1 < c)
move_east[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j + 1];
if (i + 1 < r)
move_south[i * c + j] = empty_cell[i * c + j] & empty_cell[i * c + j + c];
}
}
//cout << endl;
ans = empty_cell;
for (int i = 0; i < m; ++i) {
char ch;
cin >> ch;
if (ch == 'N') {
ans = (ans >> c) & empty_cell;
} else if (ch == 'W') {
ans = (ans & move_west) >> 1;
} else if (ch == 'E') {
ans = (ans & move_east) << 1;
} else if (ch == 'S') {
ans = (ans & move_south) << c;
} else {
ans = empty_cell & ((ans >> c) | ((ans & move_west) >> 1) | ((ans & move_east) << 1) | ((ans & move_south) << c));
}
//cout << endl;
//for (int l = 0; l < r; ++l) {
//for (int j = 0; j < c; ++j) {
//cout << ans[l * c + j];
//}
//cout << endl;
//}
}
cout << ans.count() << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
680 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
680 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
680 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
680 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
5 ms |
684 KB |
Output is correct |
14 |
Correct |
5 ms |
680 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
7 ms |
752 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
720 KB |
Output is correct |
19 |
Correct |
6 ms |
732 KB |
Output is correct |
20 |
Correct |
5 ms |
724 KB |
Output is correct |
21 |
Correct |
6 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
680 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
680 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
724 KB |
Output is correct |
13 |
Correct |
5 ms |
684 KB |
Output is correct |
14 |
Correct |
5 ms |
680 KB |
Output is correct |
15 |
Correct |
5 ms |
724 KB |
Output is correct |
16 |
Correct |
7 ms |
752 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
720 KB |
Output is correct |
19 |
Correct |
6 ms |
732 KB |
Output is correct |
20 |
Correct |
5 ms |
724 KB |
Output is correct |
21 |
Correct |
6 ms |
720 KB |
Output is correct |
22 |
Correct |
121 ms |
980 KB |
Output is correct |
23 |
Correct |
126 ms |
1080 KB |
Output is correct |
24 |
Correct |
124 ms |
980 KB |
Output is correct |
25 |
Correct |
115 ms |
1084 KB |
Output is correct |
26 |
Correct |
111 ms |
1076 KB |
Output is correct |
27 |
Correct |
183 ms |
1100 KB |
Output is correct |
28 |
Correct |
193 ms |
1084 KB |
Output is correct |
29 |
Correct |
188 ms |
1080 KB |
Output is correct |
30 |
Correct |
184 ms |
972 KB |
Output is correct |
31 |
Correct |
176 ms |
1080 KB |
Output is correct |
32 |
Correct |
230 ms |
1044 KB |
Output is correct |
33 |
Correct |
226 ms |
980 KB |
Output is correct |
34 |
Correct |
236 ms |
1048 KB |
Output is correct |
35 |
Correct |
288 ms |
940 KB |
Output is correct |
36 |
Correct |
234 ms |
1048 KB |
Output is correct |