#include <bits/stdc++.h>
using namespace std;
const int SZ = 502;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
int r, c, m;
cin >> r >> c >> m;
vector<bitset<SZ>> g(r + 2);
for(int i = 1; i <= r; i++){
string t;
cin >> t;
for(int j = 0; j < c; j++){
if(t[j] == '.') g[i][c - j] = 1;
}
//cerr << t << "\n";
//cerr << g[i] << "\n";
}
//for(int i = 0; i <= r + 1; i++) cerr << g[i] << "\n";
string s;
cin >> s;
vector<vector<bitset<SZ>>> dp(2, vector<bitset<SZ>>(r + 2));
int now = 0;
dp[now] = g;
for(char d : s){
now = !now;
for(int i = 1; i <= r; i++) dp[now][i].reset();
if(d == 'S' || d == '?'){
for(int i = 1; i <= r; i++) dp[now][i] |= dp[!now][i - 1];
}
if(d == 'N' || d == '?'){
for(int i = 1; i <= r; i++) dp[now][i] |= dp[!now][i + 1];
}
if(d == 'E' || d == '?'){
for(int i = 1; i <= r; i++) dp[now][i] |= dp[!now][i] >> 1;
}
if(d == 'W' || d == '?'){
for(int i = 1; i <= r; i++) dp[now][i] |= dp[!now][i] << 1;
}
//cerr << "test " << d << "\n";
//for(int i = 0; i <= r + 1; i++) cerr << dp2[i] << "\n";
for(int i = 1; i <= r; i++) dp[now][i] &= g[i];
//cerr << "test " << d << "\n";
//for(int i = 0; i <= r + 1; i++) cerr << dp[i] << "\n";
}
int ans = 0;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
if(dp[now][i][j]) ans++;
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
84 ms |
712 KB |
Output is correct |
23 |
Correct |
86 ms |
588 KB |
Output is correct |
24 |
Correct |
84 ms |
588 KB |
Output is correct |
25 |
Correct |
86 ms |
588 KB |
Output is correct |
26 |
Correct |
83 ms |
696 KB |
Output is correct |
27 |
Correct |
126 ms |
692 KB |
Output is correct |
28 |
Correct |
129 ms |
692 KB |
Output is correct |
29 |
Correct |
124 ms |
696 KB |
Output is correct |
30 |
Correct |
123 ms |
696 KB |
Output is correct |
31 |
Correct |
123 ms |
716 KB |
Output is correct |
32 |
Correct |
151 ms |
708 KB |
Output is correct |
33 |
Correct |
150 ms |
700 KB |
Output is correct |
34 |
Correct |
157 ms |
692 KB |
Output is correct |
35 |
Correct |
151 ms |
588 KB |
Output is correct |
36 |
Correct |
159 ms |
716 KB |
Output is correct |