#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500;
const int MAX_M = 500;
const int MAX_K = 5000;
char mat[MAX_N + 2][MAX_M];
bitset<MAX_M> dp[MAX_K + 1][MAX_N + 2], line[MAX_N + 2];
int main() {
int n, m, k;
cin >> n >> m >> k;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 0; c < m; c++ )
cin >> mat[l][c];
}
string moves;
cin >> moves;
moves = " " + moves;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 0; c < m; c++ ) {
if ( mat[l][c] == '.' )
dp[0][l][c] = line[l][c] = true;
}
}
for ( int i = 1; i <= k; i++ ) {
for ( int l = 1; l <= n; l++ ) {
dp[i][l].reset();
if ( moves[i] == 'N' )
dp[i][l] |= dp[i - 1][l + 1];
else if ( moves[i] == 'S' )
dp[i][l] |= dp[i - 1][l - 1];
else if ( moves[i] == 'W' )
dp[i][l] |= (dp[i - 1][l] >> 1);
else if ( moves[i] == 'E' )
dp[i][l] |= (dp[i - 1][l] << 1);
else {
dp[i][l] |= dp[i - 1][l + 1];
dp[i][l] |= dp[i - 1][l - 1];
dp[i][l] |= (dp[i - 1][l] >> 1);
dp[i][l] |= (dp[i - 1][l] << 1);
}
dp[i][l] &= line[l];
}
}
int ans = 0;
for ( int l = 1; l <= n; l++ )
ans += dp[k][l].count();
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
2 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
119 ms |
158036 KB |
Output is correct |
23 |
Correct |
94 ms |
158032 KB |
Output is correct |
24 |
Correct |
96 ms |
158032 KB |
Output is correct |
25 |
Correct |
93 ms |
158000 KB |
Output is correct |
26 |
Correct |
96 ms |
158024 KB |
Output is correct |
27 |
Correct |
121 ms |
157968 KB |
Output is correct |
28 |
Correct |
127 ms |
158128 KB |
Output is correct |
29 |
Correct |
121 ms |
158160 KB |
Output is correct |
30 |
Correct |
123 ms |
158032 KB |
Output is correct |
31 |
Correct |
121 ms |
158048 KB |
Output is correct |
32 |
Correct |
145 ms |
158036 KB |
Output is correct |
33 |
Correct |
141 ms |
158032 KB |
Output is correct |
34 |
Correct |
146 ms |
158036 KB |
Output is correct |
35 |
Correct |
142 ms |
158084 KB |
Output is correct |
36 |
Correct |
141 ms |
158112 KB |
Output is correct |