#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int M = 5005;
int n, m, q;
string s;
char mat[N][N];
bool dp[N][N][M];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// N E S W
map<char, int> mp;
bool valid(int x, int y){
return (x >= 1 && x <= n && y >= 1 && y <= m && mat[x][y] != '#');
}
int main(){
mp['N'] = 0, mp['E'] = 1, mp['S'] = 2, mp['W'] = 3;
cin >> n >> m >> q;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
cin >> mat[i][j];
cin >> s;
s = '_' + s;
for (int k = 0; k <= q; k ++){
for (int x = 1; x <= n; x ++){
for (int y = 1; y <= m; y ++){
if (!valid(x, y)) continue;
if (k == 0){
dp[x][y][k] = 1;
continue;
}
if (s[k] == '?'){
for (int d = 0; d < 4; d ++){
int nx = x + dx[d];
int ny = y + dy[d];
dp[x][y][k] |= dp[nx][ny][k - 1];
}
}
else{
int d = (mp[s[k]] + 2) % 4;
int nx = x + dx[d];
int ny = y + dy[d];
dp[x][y][k] = dp[nx][ny][k - 1];
}
}
}
}
int ans = 0;
for (int x = 1; x <= n; x ++)
for (int y = 1; y <= m; y ++)
ans += dp[x][y][q];
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62288 KB |
Output is correct |
2 |
Correct |
29 ms |
54864 KB |
Output is correct |
3 |
Correct |
29 ms |
43852 KB |
Output is correct |
4 |
Correct |
25 ms |
36676 KB |
Output is correct |
5 |
Correct |
19 ms |
27216 KB |
Output is correct |
6 |
Correct |
5 ms |
19536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62288 KB |
Output is correct |
2 |
Correct |
29 ms |
54864 KB |
Output is correct |
3 |
Correct |
29 ms |
43852 KB |
Output is correct |
4 |
Correct |
25 ms |
36676 KB |
Output is correct |
5 |
Correct |
19 ms |
27216 KB |
Output is correct |
6 |
Correct |
5 ms |
19536 KB |
Output is correct |
7 |
Correct |
35 ms |
57168 KB |
Output is correct |
8 |
Correct |
29 ms |
36424 KB |
Output is correct |
9 |
Correct |
25 ms |
34640 KB |
Output is correct |
10 |
Correct |
23 ms |
25180 KB |
Output is correct |
11 |
Correct |
4 ms |
13304 KB |
Output is correct |
12 |
Correct |
38 ms |
56904 KB |
Output is correct |
13 |
Correct |
36 ms |
51528 KB |
Output is correct |
14 |
Correct |
29 ms |
36548 KB |
Output is correct |
15 |
Correct |
18 ms |
17232 KB |
Output is correct |
16 |
Correct |
5 ms |
13136 KB |
Output is correct |
17 |
Correct |
42 ms |
55368 KB |
Output is correct |
18 |
Correct |
38 ms |
49736 KB |
Output is correct |
19 |
Correct |
27 ms |
32848 KB |
Output is correct |
20 |
Correct |
20 ms |
27248 KB |
Output is correct |
21 |
Correct |
4 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
62288 KB |
Output is correct |
2 |
Correct |
29 ms |
54864 KB |
Output is correct |
3 |
Correct |
29 ms |
43852 KB |
Output is correct |
4 |
Correct |
25 ms |
36676 KB |
Output is correct |
5 |
Correct |
19 ms |
27216 KB |
Output is correct |
6 |
Correct |
5 ms |
19536 KB |
Output is correct |
7 |
Correct |
35 ms |
57168 KB |
Output is correct |
8 |
Correct |
29 ms |
36424 KB |
Output is correct |
9 |
Correct |
25 ms |
34640 KB |
Output is correct |
10 |
Correct |
23 ms |
25180 KB |
Output is correct |
11 |
Correct |
4 ms |
13304 KB |
Output is correct |
12 |
Correct |
38 ms |
56904 KB |
Output is correct |
13 |
Correct |
36 ms |
51528 KB |
Output is correct |
14 |
Correct |
29 ms |
36548 KB |
Output is correct |
15 |
Correct |
18 ms |
17232 KB |
Output is correct |
16 |
Correct |
5 ms |
13136 KB |
Output is correct |
17 |
Correct |
42 ms |
55368 KB |
Output is correct |
18 |
Correct |
38 ms |
49736 KB |
Output is correct |
19 |
Correct |
27 ms |
32848 KB |
Output is correct |
20 |
Correct |
20 ms |
27248 KB |
Output is correct |
21 |
Correct |
4 ms |
15184 KB |
Output is correct |
22 |
Runtime error |
163 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |