#include <iostream>
#include <bitset>
#include <cmath>
#include <cassert>
#define X first
#define Y second
#define ll long long
#define MP make_pair
using namespace std;
const int N = 501, INF = 1e8;
const ll mod = 1e9 + 7;
int n, m, q;
string Q;
bitset<N*N> dp, res, mask;
void prints() {
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= m;j++) {
cout << dp[i * N + j];
}
cout << "\n";
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++) {
char x;
cin >> x;
dp[i * N + j] = (x != '#');
mask[i * N + j] = (x != '#');
}
cin >> Q;
for(int i = 0;i < q;i++) {
res.reset();
if(Q[i] == 'N' || Q[i] == '?')
res |= dp >> N;
if(Q[i] == 'S' || Q[i] == '?')
res |= dp << N;
if(Q[i] == 'W' || Q[i] == '?')
res |= dp >> 1;
if(Q[i] == 'E' || Q[i] == '?')
res |= dp << 1;
dp = res & mask;
}
cout << dp.count();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
380 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Correct |
5 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
380 KB |
Output is correct |
12 |
Correct |
4 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
4 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Correct |
5 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
107 ms |
716 KB |
Output is correct |
23 |
Correct |
119 ms |
716 KB |
Output is correct |
24 |
Correct |
115 ms |
716 KB |
Output is correct |
25 |
Correct |
107 ms |
716 KB |
Output is correct |
26 |
Correct |
105 ms |
716 KB |
Output is correct |
27 |
Correct |
156 ms |
716 KB |
Output is correct |
28 |
Correct |
168 ms |
720 KB |
Output is correct |
29 |
Correct |
170 ms |
676 KB |
Output is correct |
30 |
Correct |
158 ms |
716 KB |
Output is correct |
31 |
Correct |
153 ms |
716 KB |
Output is correct |
32 |
Correct |
197 ms |
716 KB |
Output is correct |
33 |
Correct |
199 ms |
716 KB |
Output is correct |
34 |
Correct |
196 ms |
716 KB |
Output is correct |
35 |
Correct |
204 ms |
812 KB |
Output is correct |
36 |
Correct |
205 ms |
716 KB |
Output is correct |