#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
const int oo = 1e9 + 7;
int r, c, m;
bitset<501> grid[502];
bitset<501> dp[502][5001];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> r >> c >> m;
for(int l = 1; l <= r; l++) {
for(int i = 1; i <= c; i++) {
char ch; cin >> ch;
if(ch == '.') grid[l][i] = 1;
dp[l][0][i] = grid[l][i];
}
}
string s; cin >> s;
for(int l = 1; l <= m; l++) {
for(int i = 1; i <= r; i++) {
if(s[l - 1] == 'S') dp[i][l] = dp[i - 1][l - 1] & grid[i];
if(s[l - 1] == 'N') dp[i][l] = dp[i + 1][l - 1] & grid[i];
if(s[l - 1] == 'E') dp[i][l] = (dp[i][l - 1] << 1) & grid[i];
if(s[l - 1] == 'W') dp[i][l] = (dp[i][l - 1] >> 1) & grid[i];
if(s[l - 1] == '?')
dp[i][l] = (dp[i + 1][l - 1] | dp[i - 1][l - 1] | (dp[i][l - 1] << 1) | (dp[i][l - 1] >> 1)) & grid[i];
}
}
int res = 0;
for(int l = 1; l <= r; l++) res += dp[l][m].count();
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
81 ms |
156880 KB |
Output is correct |
23 |
Correct |
84 ms |
157188 KB |
Output is correct |
24 |
Correct |
93 ms |
157104 KB |
Output is correct |
25 |
Correct |
90 ms |
157084 KB |
Output is correct |
26 |
Correct |
83 ms |
157048 KB |
Output is correct |
27 |
Correct |
114 ms |
157136 KB |
Output is correct |
28 |
Correct |
100 ms |
157124 KB |
Output is correct |
29 |
Correct |
103 ms |
157084 KB |
Output is correct |
30 |
Correct |
102 ms |
157188 KB |
Output is correct |
31 |
Correct |
89 ms |
157148 KB |
Output is correct |
32 |
Correct |
106 ms |
157160 KB |
Output is correct |
33 |
Correct |
107 ms |
157152 KB |
Output is correct |
34 |
Correct |
99 ms |
157132 KB |
Output is correct |
35 |
Correct |
97 ms |
157096 KB |
Output is correct |
36 |
Correct |
100 ms |
157060 KB |
Output is correct |