#include<iostream>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int nax = 501;
char grid[nax][nax];
vector<vector<int>>dp_new(nax, vector<int>(nax, 0));
vector<vector<int>>dp_old(nax, vector<int>(nax, 0));
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> grid[i][j];
}
}
string s;
cin >> s;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
dp_old[i][j] = (grid[i][j] == '.' ? 1 : 0);
}
}
for (int t = 1; t <= k; t++){
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (grid[i][j] == '#')continue;
if (s[t - 1] == 'N' || s[t - 1] == '?'){
if (i != n - 1)dp_new[i][j] |= dp_old[i + 1][j];
}
if (s[t - 1] == 'S' || s[t - 1] == '?'){
if (i)dp_new[i][j] |= dp_old[i - 1][j];
}
if (s[t - 1] == 'E' || s[t - 1] == '?'){
if (j)dp_new[i][j] |= dp_old[i][j - 1];
}
if (s[t - 1] == 'W' || s[t - 1] == '?'){
if (j != m - 1){
dp_new[i][j] |= dp_old[i][j + 1];
}
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
dp_old[i][j] = dp_new[i][j];
dp_new[i][j] = 0;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
ans += dp_old[i][j];
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
7 ms |
2260 KB |
Output is correct |
4 |
Correct |
8 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
2388 KB |
Output is correct |
6 |
Correct |
3 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
7 ms |
2260 KB |
Output is correct |
4 |
Correct |
8 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
2388 KB |
Output is correct |
6 |
Correct |
3 ms |
2388 KB |
Output is correct |
7 |
Correct |
6 ms |
2388 KB |
Output is correct |
8 |
Correct |
8 ms |
2388 KB |
Output is correct |
9 |
Correct |
7 ms |
2388 KB |
Output is correct |
10 |
Correct |
5 ms |
2400 KB |
Output is correct |
11 |
Correct |
3 ms |
2388 KB |
Output is correct |
12 |
Correct |
7 ms |
2260 KB |
Output is correct |
13 |
Correct |
8 ms |
2388 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
4 ms |
2388 KB |
Output is correct |
16 |
Correct |
3 ms |
2340 KB |
Output is correct |
17 |
Correct |
8 ms |
2304 KB |
Output is correct |
18 |
Correct |
8 ms |
2392 KB |
Output is correct |
19 |
Correct |
6 ms |
2392 KB |
Output is correct |
20 |
Correct |
4 ms |
2388 KB |
Output is correct |
21 |
Correct |
3 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
7 ms |
2260 KB |
Output is correct |
4 |
Correct |
8 ms |
2388 KB |
Output is correct |
5 |
Correct |
5 ms |
2388 KB |
Output is correct |
6 |
Correct |
3 ms |
2388 KB |
Output is correct |
7 |
Correct |
6 ms |
2388 KB |
Output is correct |
8 |
Correct |
8 ms |
2388 KB |
Output is correct |
9 |
Correct |
7 ms |
2388 KB |
Output is correct |
10 |
Correct |
5 ms |
2400 KB |
Output is correct |
11 |
Correct |
3 ms |
2388 KB |
Output is correct |
12 |
Correct |
7 ms |
2260 KB |
Output is correct |
13 |
Correct |
8 ms |
2388 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
4 ms |
2388 KB |
Output is correct |
16 |
Correct |
3 ms |
2340 KB |
Output is correct |
17 |
Correct |
8 ms |
2304 KB |
Output is correct |
18 |
Correct |
8 ms |
2392 KB |
Output is correct |
19 |
Correct |
6 ms |
2392 KB |
Output is correct |
20 |
Correct |
4 ms |
2388 KB |
Output is correct |
21 |
Correct |
3 ms |
2388 KB |
Output is correct |
22 |
Execution timed out |
1063 ms |
2772 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |