#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int G[maxn][maxn], dp[maxn][maxn][2], n, m, Q;
int main(){
cin >> n >> m >> Q;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
char c; cin >> c;
G[i][j] = (c == '.');
dp[i][j][0] = G[i][j];
}
}
string s; cin >> s;
for(int i = 0; i < Q; ++i){
for(int j = 0; j < n; ++j){
for(int k = 0; k < m; ++k){
int cur = 0;
if(s[i] == '?'){
if(j)cur |= dp[j-1][k][i&1];
if(j!=n-1)cur |= dp[j+1][k][i&1];
if(k)cur |= dp[j][k-1][i&1];
if(k!=m-1)cur |= dp[j][k+1][i&1];
}
if(s[i] == 'N' && j != n-1)cur|=dp[j+1][k][i&1];
if(s[i] == 'E' && k)cur|=dp[j][k-1][i&1];
if(s[i] == 'S' && j)cur|=dp[j-1][k][i&1];
if(s[i] == 'W' && k != m-1)cur|=dp[j][k+1][i&1];
dp[j][k][(i+1)&1] = cur&G[j][k];
}
}
}
int ans = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
ans+=dp[i][j][Q&1];
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
896 KB |
Output is correct |
2 |
Correct |
4 ms |
896 KB |
Output is correct |
3 |
Correct |
4 ms |
896 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
896 KB |
Output is correct |
2 |
Correct |
4 ms |
896 KB |
Output is correct |
3 |
Correct |
4 ms |
896 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
896 KB |
Output is correct |
7 |
Correct |
4 ms |
896 KB |
Output is correct |
8 |
Correct |
4 ms |
896 KB |
Output is correct |
9 |
Correct |
4 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
4 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Correct |
4 ms |
896 KB |
Output is correct |
15 |
Correct |
4 ms |
896 KB |
Output is correct |
16 |
Correct |
4 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
4 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
1024 KB |
Output is correct |
21 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
896 KB |
Output is correct |
2 |
Correct |
4 ms |
896 KB |
Output is correct |
3 |
Correct |
4 ms |
896 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
896 KB |
Output is correct |
6 |
Correct |
4 ms |
896 KB |
Output is correct |
7 |
Correct |
4 ms |
896 KB |
Output is correct |
8 |
Correct |
4 ms |
896 KB |
Output is correct |
9 |
Correct |
4 ms |
896 KB |
Output is correct |
10 |
Correct |
4 ms |
896 KB |
Output is correct |
11 |
Correct |
4 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Correct |
4 ms |
896 KB |
Output is correct |
15 |
Correct |
4 ms |
896 KB |
Output is correct |
16 |
Correct |
4 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
896 KB |
Output is correct |
19 |
Correct |
4 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
1024 KB |
Output is correct |
21 |
Correct |
5 ms |
896 KB |
Output is correct |
22 |
Execution timed out |
1080 ms |
3584 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |