#include <bits/stdc++.h>
using namespace std;
const int N = 505;
bitset<N * N> bs, allowed, west, east;
int main() {
int r, c, m;
cin >> r >> c >> m;
auto Get = [&](int i, int j) {
return i * c + j;
};
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
char v;
cin >> v;
if (v == '.') {
bs[Get(i, j)] = allowed[Get(i, j)] = true;
}
}
}
west.set();
east.set();
for (int i = 0; i < r; i++) {
west[Get(i, 0)] = east[Get(i, c - 1)] = false;
}
string s;
cin >> s;
for (auto d : s) {
if (d == '?') {
bs = (((bs & east) << 1) | ((bs & west) >> 1) | (bs << c) | (bs >> c)) & allowed;
} else if (d == 'N') {
bs = (bs >> c) & allowed;
} else if (d == 'S') {
bs = (bs << c) & allowed;
} else if (d == 'W') {
bs = ((bs & west) >> 1) & allowed;
} else {
bs = ((bs & east) << 1) & allowed;
}
}
cout << bs.count() << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
628 KB |
Output is correct |
21 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
628 KB |
Output is correct |
21 |
Correct |
4 ms |
724 KB |
Output is correct |
22 |
Correct |
90 ms |
1008 KB |
Output is correct |
23 |
Correct |
89 ms |
1012 KB |
Output is correct |
24 |
Correct |
86 ms |
1008 KB |
Output is correct |
25 |
Correct |
85 ms |
980 KB |
Output is correct |
26 |
Correct |
83 ms |
988 KB |
Output is correct |
27 |
Correct |
132 ms |
980 KB |
Output is correct |
28 |
Correct |
133 ms |
980 KB |
Output is correct |
29 |
Correct |
133 ms |
1000 KB |
Output is correct |
30 |
Correct |
133 ms |
1012 KB |
Output is correct |
31 |
Correct |
137 ms |
988 KB |
Output is correct |
32 |
Correct |
170 ms |
1000 KB |
Output is correct |
33 |
Correct |
171 ms |
1008 KB |
Output is correct |
34 |
Correct |
168 ms |
1008 KB |
Output is correct |
35 |
Correct |
187 ms |
1108 KB |
Output is correct |
36 |
Correct |
169 ms |
984 KB |
Output is correct |