#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ii pair<int , int>
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
//#define int long long
const int inf = 1e9 + 7;
const int MAX_N = 5e2 + 7;
const int MOD = 1e9 + 7;
char a[MAX_N][MAX_N];
char s[5007];
bitset<507> dp[2][MAX_N];
bitset<507> d[MAX_N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int n , m , l; cin >> n >> m >> l;
//subtask 3
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
cin >> a[i][j];
if (a[i][j] == '#') {
d[i][j] = 0;
dp[1][i][j] = 0;
}
else {
d[i][j] = 1;
dp[1][i][j] = 1;
}
}
}
for (int i = 0 ; i < l ; i++) {
cin >> s[i];
}
for (int i = 0 ; i < l ; i++) {
int now = i & 1;
int prev = now ^ 1;
for (int j = 0 ; j < n ; j++) {
if (s[i] == 'W') {
dp[now][j] = dp[prev][j] >> 1;
}
else if (s[i] == 'E') {
dp[now][j] = dp[prev][j] << 1;
}
else if (s[i] == 'S') {
dp[now][j] = dp[prev][j - 1];
}
else if (s[i] == 'N') {
dp[now][j] = dp[prev][j + 1];
}
else if (s[i] == '?') {
dp[now][j] = (dp[prev][j] >> 1);
dp[now][j] |= (dp[prev][j] << 1);
if ((j - 1) >= 0)
dp[now][j] |= dp[prev][j - 1];
if ((j + 1) < n)
dp[now][j] |= dp[prev][j + 1];
}
}
for (int j = 0 ; j < n ; j++) {
dp[now][j] = dp[now][j] & d[j];
dp[prev][j] = dp[now][j];
}
// for (int j = 0 ; j < n ; j++) {
// dp[now][j].reset
// }
}
int ans = 0;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
if (dp[(l - 1) & 1][i][j]) {
ans++;
}
//cout << dp[(l - 1) & 1][i][j] << " ";
}
//cout << '\n';
}
cout << ans;
//}
return 0;
}
// 1 1 0 0 0 0 1 1 0
// 1 1 0 0 0 0 1 1 0
// 1 1 0 1 1 1 1 0 0
// 1 0 0 1 1 1 0 1 0
// 1 0 1 1 0 1 1 1 1
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 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 |
1 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
44 ms |
612 KB |
Output is correct |
23 |
Correct |
37 ms |
652 KB |
Output is correct |
24 |
Correct |
37 ms |
596 KB |
Output is correct |
25 |
Correct |
50 ms |
652 KB |
Output is correct |
26 |
Correct |
32 ms |
660 KB |
Output is correct |
27 |
Correct |
48 ms |
652 KB |
Output is correct |
28 |
Correct |
50 ms |
904 KB |
Output is correct |
29 |
Correct |
51 ms |
852 KB |
Output is correct |
30 |
Correct |
48 ms |
852 KB |
Output is correct |
31 |
Correct |
47 ms |
840 KB |
Output is correct |
32 |
Correct |
57 ms |
836 KB |
Output is correct |
33 |
Correct |
62 ms |
968 KB |
Output is correct |
34 |
Correct |
63 ms |
852 KB |
Output is correct |
35 |
Correct |
61 ms |
912 KB |
Output is correct |
36 |
Correct |
57 ms |
904 KB |
Output is correct |