#include "bits/stdc++.h"
using namespace std;
int a, b, m;
vector<vector<bool> > grid;
string s;
bool valid(int x, int y) {
// cout << "! " << x << ' ' << y << endl;
if (x < 0 || y < 0) return false;
if (x >= a || y >= b) return false;
return grid[x][y];
}
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
cin >> a >> b >> m;
for (int i=0; i<a; i++) {
string s;
cin >> s;
vector<bool> tr(b);
for (int j=0; j<b; j++) {
tr[j] = (s[j] == '.');
}
grid.push_back(tr);
}
cin >> s;
s = ' ' + s;
bool reach[a][b][m+1];
memset(reach, 0, sizeof reach);
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
reach[i][j][0] = valid(i, j);
}
}
for (int STEP=1; STEP<=m; STEP++) {
// ith step
char st = s[STEP];
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
if (valid(i, j)) {
if (st == 'W') {
reach[i][j][STEP] = (valid(i, j+1) && reach[i][j+1][STEP-1]);
}
else if (st == 'E') {
reach[i][j][STEP] = (valid(i, j-1) && reach[i][j-1][STEP-1]);
}
else if (st == 'N') {
reach[i][j][STEP] = (valid(i+1, j) && reach[i+1][j][STEP-1]);
}
else if (st == 'S') {
reach[i][j][STEP] = (valid(i-1, j) && reach[i-1][j][STEP-1]);
}
else {
reach[i][j][STEP] = false;
for (int k=0; k<4; k++) {
reach[i][j][STEP] |= (valid(i+dx[k], j+dy[k]) && reach[i+dx[k]][j+dy[k]][STEP-1]);
}
}
}
else {
reach[i][j][STEP] = false;
}
}
}
}
int c = 0;
for (int i=0; i<a; i++) {
for (int j=0; j<b; j++) {
if (reach[i][j][m]) c++;
}
}
cout << c << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1272 KB |
Output is correct |
2 |
Correct |
17 ms |
1276 KB |
Output is correct |
3 |
Correct |
20 ms |
1272 KB |
Output is correct |
4 |
Correct |
18 ms |
1272 KB |
Output is correct |
5 |
Correct |
15 ms |
1272 KB |
Output is correct |
6 |
Correct |
13 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1272 KB |
Output is correct |
2 |
Correct |
17 ms |
1276 KB |
Output is correct |
3 |
Correct |
20 ms |
1272 KB |
Output is correct |
4 |
Correct |
18 ms |
1272 KB |
Output is correct |
5 |
Correct |
15 ms |
1272 KB |
Output is correct |
6 |
Correct |
13 ms |
1272 KB |
Output is correct |
7 |
Correct |
20 ms |
1272 KB |
Output is correct |
8 |
Correct |
24 ms |
1272 KB |
Output is correct |
9 |
Correct |
22 ms |
1272 KB |
Output is correct |
10 |
Correct |
17 ms |
1272 KB |
Output is correct |
11 |
Correct |
14 ms |
1272 KB |
Output is correct |
12 |
Correct |
28 ms |
1272 KB |
Output is correct |
13 |
Correct |
30 ms |
1276 KB |
Output is correct |
14 |
Correct |
32 ms |
1272 KB |
Output is correct |
15 |
Correct |
18 ms |
1272 KB |
Output is correct |
16 |
Correct |
14 ms |
1272 KB |
Output is correct |
17 |
Correct |
32 ms |
1144 KB |
Output is correct |
18 |
Correct |
36 ms |
1272 KB |
Output is correct |
19 |
Correct |
30 ms |
1272 KB |
Output is correct |
20 |
Correct |
19 ms |
1272 KB |
Output is correct |
21 |
Correct |
14 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1272 KB |
Output is correct |
2 |
Correct |
17 ms |
1276 KB |
Output is correct |
3 |
Correct |
20 ms |
1272 KB |
Output is correct |
4 |
Correct |
18 ms |
1272 KB |
Output is correct |
5 |
Correct |
15 ms |
1272 KB |
Output is correct |
6 |
Correct |
13 ms |
1272 KB |
Output is correct |
7 |
Correct |
20 ms |
1272 KB |
Output is correct |
8 |
Correct |
24 ms |
1272 KB |
Output is correct |
9 |
Correct |
22 ms |
1272 KB |
Output is correct |
10 |
Correct |
17 ms |
1272 KB |
Output is correct |
11 |
Correct |
14 ms |
1272 KB |
Output is correct |
12 |
Correct |
28 ms |
1272 KB |
Output is correct |
13 |
Correct |
30 ms |
1276 KB |
Output is correct |
14 |
Correct |
32 ms |
1272 KB |
Output is correct |
15 |
Correct |
18 ms |
1272 KB |
Output is correct |
16 |
Correct |
14 ms |
1272 KB |
Output is correct |
17 |
Correct |
32 ms |
1144 KB |
Output is correct |
18 |
Correct |
36 ms |
1272 KB |
Output is correct |
19 |
Correct |
30 ms |
1272 KB |
Output is correct |
20 |
Correct |
19 ms |
1272 KB |
Output is correct |
21 |
Correct |
14 ms |
1272 KB |
Output is correct |
22 |
Runtime error |
247 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
23 |
Halted |
0 ms |
0 KB |
- |