#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
bitset<maxn> G[maxn], dp[maxn][2];
int n, m, Q;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> Q;
for(int i = 1; i <= n; ++i){
for(int j = 0; j < m; ++j){
char c; cin >> c;
G[i][j] = (c == '.');
}
dp[i][0] = G[i];
}
string s; cin >> s;
for(int i = 0; i < Q; ++i){
for(int j = 1; j <= n; ++j){
if(s[i] == '?')dp[j][(i+1)&1] = dp[j+1][i&1] | dp[j-1][i&1] | (dp[j][i&1]<<1) | (dp[j][i&1] >> 1);
if(s[i] == 'N')dp[j][(i+1)&1] = dp[j+1][i&1];
if(s[i] == 'E')dp[j][(i+1)&1] = dp[j][i&1]<<1;
if(s[i] == 'W')dp[j][(i+1)&1] = dp[j][i&1]>>1;
if(s[i] == 'S')dp[j][(i+1)&1] = dp[j-1][i&1];
dp[j][(i+1)&1]&=G[j];
}
}
int ans = 0;
for(int i = 1; i <= n; ++i){
ans+=dp[i][Q&1].count();
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
85 ms |
384 KB |
Output is correct |
23 |
Correct |
88 ms |
640 KB |
Output is correct |
24 |
Correct |
85 ms |
640 KB |
Output is correct |
25 |
Correct |
81 ms |
764 KB |
Output is correct |
26 |
Correct |
80 ms |
640 KB |
Output is correct |
27 |
Correct |
147 ms |
640 KB |
Output is correct |
28 |
Correct |
147 ms |
640 KB |
Output is correct |
29 |
Correct |
151 ms |
640 KB |
Output is correct |
30 |
Correct |
147 ms |
640 KB |
Output is correct |
31 |
Correct |
143 ms |
640 KB |
Output is correct |
32 |
Correct |
195 ms |
640 KB |
Output is correct |
33 |
Correct |
197 ms |
640 KB |
Output is correct |
34 |
Correct |
195 ms |
764 KB |
Output is correct |
35 |
Correct |
195 ms |
640 KB |
Output is correct |
36 |
Correct |
193 ms |
640 KB |
Output is correct |