//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500;
bitset<N> dp[2][N];
bitset<N> water[N];
int r, c;
void hor_shift(int u, int s) {
if (s > 0) {
for (int i = 0; i < r; i++) {
dp[u][i] |= dp[u ^ 1][i] >> 1;
}
} else {
for (int i = 0; i < r; i++) {
dp[u][i] |= dp[u ^ 1][i] << 1;
}
}
}
void ver_shift(int u, int s) {
for (int i = 0; i < r; i++) {
if (i + s >= 0 && i + s < r) {
dp[u][i] |= dp[u ^ 1][i + s];
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int m;
cin >> r >> c >> m;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
char a;
cin >> a;
if (a == '.') {
water[i].set(j);
dp[0][i][j] = 1;
}
}
}
string t;
cin >> t;
int v = 0;
for (char c : t) {
int u = v ^ 1;
for (int i = 0; i < r; i++) {
dp[u][i].reset();
}
if (c == 'N') {
ver_shift(u, 1);
}
if (c == 'S') {
ver_shift(u, -1);
}
if (c == 'E') {
hor_shift(u, -1);
}
if (c == 'W') {
hor_shift(u, 1);
}
if (c == '?') {
ver_shift(u, 1);
ver_shift(u, -1);
hor_shift(u, 1);
hor_shift(u, -1);
}
for (int i = 0; i < r; i++) {
dp[u][i] &= water[i];
}
v ^= 1;
}
int ans = 0;
for (int i = 0; i < r; i++) {
ans += dp[m & 1][i].count();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
380 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
424 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
380 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
424 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
105 ms |
760 KB |
Output is correct |
23 |
Correct |
109 ms |
736 KB |
Output is correct |
24 |
Correct |
102 ms |
760 KB |
Output is correct |
25 |
Correct |
102 ms |
736 KB |
Output is correct |
26 |
Correct |
100 ms |
760 KB |
Output is correct |
27 |
Correct |
147 ms |
732 KB |
Output is correct |
28 |
Correct |
149 ms |
636 KB |
Output is correct |
29 |
Correct |
151 ms |
760 KB |
Output is correct |
30 |
Correct |
149 ms |
744 KB |
Output is correct |
31 |
Correct |
147 ms |
876 KB |
Output is correct |
32 |
Correct |
188 ms |
772 KB |
Output is correct |
33 |
Correct |
183 ms |
760 KB |
Output is correct |
34 |
Correct |
283 ms |
632 KB |
Output is correct |
35 |
Correct |
184 ms |
632 KB |
Output is correct |
36 |
Correct |
183 ms |
716 KB |
Output is correct |