#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
int r, c, m;
int d;
int cnt;
string str;
string mp[MAXN+5];
bool dp[MAXN+5][MAXN+5][2];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> r >> c >> m;
for (int i = 1; i <= r; i++) {
cin >> mp[i];
mp[i] = "#" + mp[i] + "#";
}
cin >> str;
for (int i = 0; i <= c+1; i++) {
mp[0] = mp[0] + "#";
mp[r+1] = mp[r+1] + "#";
}
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
dp[i][j][1] = (mp[i][j] != '#');
for (int k = 0; k < m; k++) {
if (str[k] == '?') {
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
for (int d = 0; d < 4 && !dp[i][j][k&1]; d++)
dp[i][j][k&1] |= ((mp[i][j] != '#') && (dp[i+dx[d]][j+dy[d]][(k+1)&1]));
} else {
if (str[k] == 'S') d = 0;
else if (str[k] == 'N') d = 1;
else if (str[k] == 'E') d = 2;
else if (str[k] == 'W') d = 3;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
dp[i][j][k&1] = ((mp[i][j] != '#') && (dp[i+dx[d]][j+dy[d]][(k+1)&1]));
}
}
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cnt += dp[i][j][(m+1)&1];
cout << cnt << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
512 KB |
Output is correct |
9 |
Incorrect |
11 ms |
512 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
8 ms |
512 KB |
Output is correct |
4 |
Correct |
9 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
6 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
512 KB |
Output is correct |
9 |
Incorrect |
11 ms |
512 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |