#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500;
const int MAX_K = 5000;
char mat[MAX_N + 2][MAX_N + 2];
set <pair <int, int>> dp[MAX_K + 1];
int dl[4] = { -1, 0, 1, 0 };
int dc[4] = { 0, -1, 0, 1 };
int dir[256];
int main() {
int n, m, k;
dir['N'] = 0;
dir['W'] = 1;
dir['S'] = 2;
dir['E'] = 3;
cin >> n >> m >> k;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ )
cin >> mat[l][c];
}
for ( int l = 0; l <= n + 1; l++ )
mat[l][0] = mat[l][m + 1] = '#';
for ( int c = 0; c <= m + 1; c++ )
mat[0][c] = mat[n + 1][c] = '#';
string moves;
cin >> moves;
moves = " " + moves;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ ) {
if ( mat[l][c] == '.' )
dp[0].insert( { l, c } );
}
}
for ( int i = 1; i <= k; i++ ) {
for ( pair <int, int> p: dp[i - 1] ) {
if ( moves[i] == '?' ) {
for ( int d = 0; d < 4; d++ ) {
int l = p.first + dl[d], c = p.second + dc[d];
if ( mat[l][c] == '.' )
dp[i].insert( { l, c } );
}
} else {
int d = dir[moves[i]];
int l = p.first + dl[d], c = p.second + dc[d];
if ( mat[l][c] == '.' )
dp[i].insert( { l, c } );
}
}
}
cout << dp[k].size();
return 0;
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:50:37: warning: array subscript has type 'char' [-Wchar-subscripts]
50 | int d = dir[moves[i]];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
42580 KB |
Output is correct |
2 |
Correct |
7 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
42580 KB |
Output is correct |
2 |
Correct |
7 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
176 ms |
46932 KB |
Output is correct |
8 |
Correct |
30 ms |
9040 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
282 ms |
48068 KB |
Output is correct |
13 |
Correct |
178 ms |
35480 KB |
Output is correct |
14 |
Correct |
101 ms |
22352 KB |
Output is correct |
15 |
Correct |
5 ms |
1884 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
353 ms |
48132 KB |
Output is correct |
18 |
Correct |
224 ms |
38736 KB |
Output is correct |
19 |
Correct |
75 ms |
17236 KB |
Output is correct |
20 |
Correct |
21 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
42580 KB |
Output is correct |
2 |
Correct |
7 ms |
3420 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
176 ms |
46932 KB |
Output is correct |
8 |
Correct |
30 ms |
9040 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
282 ms |
48068 KB |
Output is correct |
13 |
Correct |
178 ms |
35480 KB |
Output is correct |
14 |
Correct |
101 ms |
22352 KB |
Output is correct |
15 |
Correct |
5 ms |
1884 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
353 ms |
48132 KB |
Output is correct |
18 |
Correct |
224 ms |
38736 KB |
Output is correct |
19 |
Correct |
75 ms |
17236 KB |
Output is correct |
20 |
Correct |
21 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Execution timed out |
1060 ms |
253212 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |