#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 500 + 5;
const int inf = 2e9;
const int mod = 1e9 + 7;
bitset<N> a[N], dp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
string s; cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '.') a[i][j] = dp[i][j] = 1;
else a[i][j] = dp[i][j] = 0;
}
}
string str; cin >> str;
for (int z = 0; z < k; z++) {
char ch = str[z];
bitset<N> ndp[N];
for (int i = 0; i < n; i++) {
if (ch == 'N' && i < n - 1) ndp[i] = dp[i + 1];
if (ch == 'S' && i > 0) ndp[i] = dp[i - 1];
if (ch == 'W') ndp[i] = (dp[i] >> 1);
if (ch == 'E') ndp[i] = (dp[i] << 1);
if (ch == '?') {
if (i < n - 1) ndp[i] |= dp[i + 1];
if (i > 0) ndp[i] |= dp[i - 1];
ndp[i] |= (dp[i] << 1);
ndp[i] |= (dp[i] >> 1);
}
ndp[i] &= a[i];
}
swap(dp, ndp);
}
int ans = 0;
for (int i = 0; i < n; i++) ans += dp[i].count();
cout << ans << en;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
396 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
396 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
68 ms |
604 KB |
Output is correct |
23 |
Correct |
70 ms |
672 KB |
Output is correct |
24 |
Correct |
67 ms |
724 KB |
Output is correct |
25 |
Correct |
65 ms |
596 KB |
Output is correct |
26 |
Correct |
65 ms |
596 KB |
Output is correct |
27 |
Correct |
105 ms |
668 KB |
Output is correct |
28 |
Correct |
109 ms |
664 KB |
Output is correct |
29 |
Correct |
119 ms |
668 KB |
Output is correct |
30 |
Correct |
109 ms |
668 KB |
Output is correct |
31 |
Correct |
103 ms |
592 KB |
Output is correct |
32 |
Correct |
139 ms |
676 KB |
Output is correct |
33 |
Correct |
132 ms |
596 KB |
Output is correct |
34 |
Correct |
133 ms |
672 KB |
Output is correct |
35 |
Correct |
133 ms |
596 KB |
Output is correct |
36 |
Correct |
132 ms |
596 KB |
Output is correct |