#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const int inf = 1000000000;
#define int long long
#define F first
#define S second
#define pb push_back
#define ppb pop_back
int r, c, m, ans;
bool block[N][N], ok[N][N][N], used[N][N][N];
char s[5005];
void rec(int x, int y, int step){
used[x][y][step] = 1;
if(step == 0){
ok[x][y][step] = 1;
return;
}
if(s[step] == '?'){
if(!block[x + 1][y] && !used[x + 1][y][step - 1]) rec(x + 1, y, step - 1);
if(ok[x + 1][y][step - 1]) ok[x][y][step] = 1;
if(!block[x - 1][y] && !used[x - 1][y][step - 1]) rec(x - 1, y, step - 1);
if(ok[x - 1][y][step - 1]) ok[x][y][step] = 1;
if(!block[x][y + 1] && !used[x][y + 1][step - 1]) rec(x, y + 1, step - 1);
if(ok[x][y + 1][step - 1]) ok[x][y][step] = 1;
if(!block[x][y - 1] && !used[x][y - 1][step - 1]) rec(x, y - 1, step - 1);
if(ok[x][y - 1][step - 1]) ok[x][y][step] = 1;
}
else if(s[step] == 'N'){
if(!block[x + 1][y] && !used[x + 1][y][step - 1]) rec(x + 1, y, step - 1);
if(ok[x + 1][y][step - 1]) ok[x][y][step] = 1;
}
else if(s[step] == 'S'){
if(!block[x - 1][y] && !used[x - 1][y][step - 1]) rec(x - 1, y, step - 1);
if(ok[x - 1][y][step - 1]) ok[x][y][step] = 1;
}
else if(s[step] == 'W'){
if(!block[x][y + 1] && !used[x][y + 1][step - 1]) rec(x, y + 1, step - 1);
if(ok[x][y + 1][step - 1]) ok[x][y][step] = 1;
}
else{
if(!block[x][y - 1] && !used[x][y - 1][step - 1]) rec(x, y - 1, step - 1);
if(ok[x][y - 1][step - 1]) ok[x][y][step] = 1;
}
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> r >> c >> m;
for(int i = 1; i <= r; ++i){
block[i][0] = 1;
block[i][c + 1] = 1;
for(int j = 1; j <= c; ++j){
char c1;
cin >> c1;
if(c1 == '#') block[i][j] = 1;
// cout << block[i][j];
}
// cout << '\n';
}
for(int j = 1; j <= c; ++j){
block[0][j] = 1;
block[r + 1][j] = 1;
}
for(int i = 1; i <= m; ++i){
cin >> s[i];
}
for(int i = 1; i <= r; ++i){
for(int j = 1; j <= c; ++j){
if(!block[i][j]){
// cout << i << ' ' << j << '\n';
rec(i, j, m);
if(ok[i][j][m]) ans++;
}
}
}
cout << ans;
return 0;
}
Compilation message
nautilus.cpp:53:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2380 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2380 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
19 ms |
2380 KB |
Output is correct |
8 |
Correct |
5 ms |
2376 KB |
Output is correct |
9 |
Correct |
2 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
1488 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
22 ms |
2496 KB |
Output is correct |
13 |
Correct |
26 ms |
2492 KB |
Output is correct |
14 |
Correct |
17 ms |
2468 KB |
Output is correct |
15 |
Correct |
2 ms |
1616 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
26 ms |
2512 KB |
Output is correct |
18 |
Correct |
25 ms |
2512 KB |
Output is correct |
19 |
Correct |
8 ms |
2384 KB |
Output is correct |
20 |
Correct |
5 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2380 KB |
Output is correct |
2 |
Correct |
2 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
19 ms |
2380 KB |
Output is correct |
8 |
Correct |
5 ms |
2376 KB |
Output is correct |
9 |
Correct |
2 ms |
1488 KB |
Output is correct |
10 |
Correct |
1 ms |
1488 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
22 ms |
2496 KB |
Output is correct |
13 |
Correct |
26 ms |
2492 KB |
Output is correct |
14 |
Correct |
17 ms |
2468 KB |
Output is correct |
15 |
Correct |
2 ms |
1616 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
26 ms |
2512 KB |
Output is correct |
18 |
Correct |
25 ms |
2512 KB |
Output is correct |
19 |
Correct |
8 ms |
2384 KB |
Output is correct |
20 |
Correct |
5 ms |
2384 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |