#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 300005
int main() {
fast
int R, C, M;
cin >> R >> C >> M;
vector<bitset<505>> sea(R);
bitset<505> dp[R+1][M+1];
for (int i = 0; i < R; i++) {
string s;
cin >> s;
for (int j = 0; j < C; j++) {
if (s[j] == '.')
sea[i][j] = 1;
}
}
bitset<505> temp;
string way;
cin >> way;
for (int i = 0; i < R; i++)
dp[i][0] = sea[i];
for (int step = 0; step < M; step++) {
for (int row = 0; row < R; row++) {
if (way[step] == 'W')
dp[row][step+1] = dp[row][step] >> 1;
else if (way[step] == 'E')
dp[row][step+1] = dp[row][step] << 1;
else if (way[step] == 'N')
dp[row][step+1] = dp[row+1][step];
else if (way[step] == 'S') {
if (row == 0)
dp[row][step+1] = temp;
else
dp[row][step+1] = dp[row-1][step];
} else {
dp[row][step+1] = (dp[row][step] << 1) | (dp[row][step] >> 1) | (dp[row+1][step]);
if (row != 0)
dp[row][step+1] = (dp[row][step+1] | dp[row-1][step]);
}
dp[row][step+1] = (dp[row][step+1] & sea[row]);
}
}
int ans = 0;
for (int i = 0; i < R; i++)
ans += dp[i][M].count();
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
964 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
964 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
968 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
1 ms |
964 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
968 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
146 ms |
157460 KB |
Output is correct |
23 |
Correct |
191 ms |
157508 KB |
Output is correct |
24 |
Correct |
148 ms |
157504 KB |
Output is correct |
25 |
Correct |
152 ms |
157404 KB |
Output is correct |
26 |
Correct |
185 ms |
157468 KB |
Output is correct |
27 |
Correct |
184 ms |
157404 KB |
Output is correct |
28 |
Correct |
191 ms |
157504 KB |
Output is correct |
29 |
Correct |
185 ms |
157388 KB |
Output is correct |
30 |
Correct |
238 ms |
157380 KB |
Output is correct |
31 |
Correct |
189 ms |
157476 KB |
Output is correct |
32 |
Correct |
227 ms |
157660 KB |
Output is correct |
33 |
Correct |
220 ms |
157388 KB |
Output is correct |
34 |
Correct |
263 ms |
157504 KB |
Output is correct |
35 |
Correct |
241 ms |
157408 KB |
Output is correct |
36 |
Correct |
260 ms |
157500 KB |
Output is correct |