#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
char mat[505][505];
bool vis[5005][505][505];
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);
}
}
// for(int p = 0; p <= k; p++) {
// if (p != 0) cout << str[p-1] << "\n";
//
// for(int i = 0; i < n; i++) {
// for(int j = 0; j < m; j++) {
// cout << vis[p][i][j] << "";
// }
// cout << "\n";
// }
// cout << "\n";
// }
int cnt = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cnt += vis[k][i][j];
}
}
cout << cnt << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5324 KB |
Output is correct |
2 |
Correct |
4 ms |
4812 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5324 KB |
Output is correct |
2 |
Correct |
4 ms |
4812 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
18 ms |
5708 KB |
Output is correct |
8 |
Correct |
10 ms |
5708 KB |
Output is correct |
9 |
Correct |
4 ms |
4428 KB |
Output is correct |
10 |
Correct |
2 ms |
2124 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
36 ms |
5676 KB |
Output is correct |
13 |
Correct |
35 ms |
5716 KB |
Output is correct |
14 |
Correct |
28 ms |
5632 KB |
Output is correct |
15 |
Correct |
5 ms |
4860 KB |
Output is correct |
16 |
Correct |
2 ms |
1100 KB |
Output is correct |
17 |
Correct |
51 ms |
5788 KB |
Output is correct |
18 |
Correct |
43 ms |
5632 KB |
Output is correct |
19 |
Correct |
14 ms |
5760 KB |
Output is correct |
20 |
Correct |
7 ms |
5708 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5324 KB |
Output is correct |
2 |
Correct |
4 ms |
4812 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
18 ms |
5708 KB |
Output is correct |
8 |
Correct |
10 ms |
5708 KB |
Output is correct |
9 |
Correct |
4 ms |
4428 KB |
Output is correct |
10 |
Correct |
2 ms |
2124 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
36 ms |
5676 KB |
Output is correct |
13 |
Correct |
35 ms |
5716 KB |
Output is correct |
14 |
Correct |
28 ms |
5632 KB |
Output is correct |
15 |
Correct |
5 ms |
4860 KB |
Output is correct |
16 |
Correct |
2 ms |
1100 KB |
Output is correct |
17 |
Correct |
51 ms |
5788 KB |
Output is correct |
18 |
Correct |
43 ms |
5632 KB |
Output is correct |
19 |
Correct |
14 ms |
5760 KB |
Output is correct |
20 |
Correct |
7 ms |
5708 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Execution timed out |
1093 ms |
135256 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |