#include <bits/stdc++.h>
using namespace std;
const int bsz = (500 * 502);
const int maxn = 500;
const int maxk = 5000;
int n, m, k;
bitset<bsz> mask;
bitset<bsz> dp[2];
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
char ch;
cin >> ch;
if(ch == '.') {
mask[j + (i - 1) * (m + 2)] = 1;
}
}
}
dp[0] = mask;
for(int i = 1; i <= k; i++) {
char ch;
cin >> ch;
bitset<bsz> &cur = dp[i % 2];
bitset<bsz> &prev = dp[1 - (i % 2)];
if(ch == 'N') {
cur = prev >> (m + 2);
}
if(ch == 'E') {
cur = prev << 1;
}
if(ch == 'S') {
cur = prev << (m + 2);
}
if(ch == 'W') {
cur = prev >> 1;
}
if(ch == '?') {
cur = prev >> (m + 2);
cur |= prev << 1;
cur |= prev << (m + 2);
cur |= prev >> 1;
}
cur &= mask;
/*for(int l = 1; l <= n; l++) {
for(int j = 1; j <= m; j++) {
cout << cur[j + (l - 1) * (m + 2)];
}
cout << "\n";
}
cout << "---\n";*/
}
cout << dp[k % 2].count() << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
//cin >> T;
while(T--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
64 ms |
348 KB |
Output is correct |
23 |
Correct |
66 ms |
604 KB |
Output is correct |
24 |
Correct |
73 ms |
600 KB |
Output is correct |
25 |
Correct |
63 ms |
604 KB |
Output is correct |
26 |
Correct |
61 ms |
560 KB |
Output is correct |
27 |
Correct |
98 ms |
348 KB |
Output is correct |
28 |
Correct |
98 ms |
604 KB |
Output is correct |
29 |
Correct |
105 ms |
580 KB |
Output is correct |
30 |
Correct |
98 ms |
604 KB |
Output is correct |
31 |
Correct |
97 ms |
348 KB |
Output is correct |
32 |
Correct |
123 ms |
580 KB |
Output is correct |
33 |
Correct |
124 ms |
604 KB |
Output is correct |
34 |
Correct |
125 ms |
580 KB |
Output is correct |
35 |
Correct |
125 ms |
348 KB |
Output is correct |
36 |
Correct |
123 ms |
556 KB |
Output is correct |