#include <bits/stdc++.h>
using namespace std;
using ll = long long;
char mat[105][105];
bool vis[105][105][105];
int n, m, k;
string str;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3
bool isValid(int x, int y) {
if (x >= n || x < 0 || y >= m || y < 0) return false;
if (mat[x][y] == '#') return false;
return true;
}
void go(int curr, int x, int y) {
if (!isValid(x, y) || vis[curr][x][y]) return;
vis[curr][x][y] = true;
if (curr == k) return;
if (str[curr] == '?') {
for(int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (isValid(nx, ny)) {
go(curr+1, nx, ny);
}
}
} else {
switch(str[curr]) {
case 'N':
go(curr+1, x+dx[NORTH], y+dy[NORTH]);
break;
case 'E':
go(curr+1, x+dx[EAST], y+dy[EAST]);
break;
case 'S':
go(curr+1, x+dx[SOUTH], y+dy[SOUTH]);
break;
case 'W':
go(curr+1, x+dx[WEST], y+dy[WEST]);
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
cin >> str;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
go(0, i, j);
}
}
int cnt = 0;
// for(int i = 0; i < n; i++) {
// for(int j = 0; j < m; j++) {
// cout << vis[k][i][j] << " ";
// }
// cout << "\n";
// }
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cnt += vis[k][i][j];
}
}
cout << cnt << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1356 KB |
Output is correct |
2 |
Correct |
2 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
844 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1356 KB |
Output is correct |
2 |
Correct |
2 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
844 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
15 ms |
1388 KB |
Output is correct |
8 |
Correct |
6 ms |
1428 KB |
Output is correct |
9 |
Correct |
3 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
31 ms |
1332 KB |
Output is correct |
13 |
Correct |
31 ms |
1376 KB |
Output is correct |
14 |
Correct |
21 ms |
1392 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
41 ms |
1412 KB |
Output is correct |
18 |
Correct |
35 ms |
1348 KB |
Output is correct |
19 |
Correct |
10 ms |
1436 KB |
Output is correct |
20 |
Correct |
4 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1356 KB |
Output is correct |
2 |
Correct |
2 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
844 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
15 ms |
1388 KB |
Output is correct |
8 |
Correct |
6 ms |
1428 KB |
Output is correct |
9 |
Correct |
3 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
31 ms |
1332 KB |
Output is correct |
13 |
Correct |
31 ms |
1376 KB |
Output is correct |
14 |
Correct |
21 ms |
1392 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
41 ms |
1412 KB |
Output is correct |
18 |
Correct |
35 ms |
1348 KB |
Output is correct |
19 |
Correct |
10 ms |
1436 KB |
Output is correct |
20 |
Correct |
4 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
716 KB |
Output is correct |
22 |
Runtime error |
2 ms |
716 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |