#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)
const int MOD = 1e9 + 7;
const int INF = 1e17;
const int N = 525;
const int LOG = 20;
bitset<N> dp[2][N];
bitset<N> A[N];
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int n, m, k;
cin>>n>>m>>k;
string s[n];
for(int i = 0;i < n;i++)cin>>s[i];
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
A[i][j] = (s[i][j] == '.');
}
}
string t;
cin>>t;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++)dp[0][i][j] = A[i][j];
}
int p = 0;
for(int i = 0;i < k;i++){
for(int j = 0; j < n;j++)dp[p ^ 1][j].reset();
for(int j = 0;j < n;j++){
if(t[i] == 'W' || t[i] == '?')dp[p ^ 1][j] |= (A[j] & (dp[p][j] >> 1));
if(t[i] == 'E' || t[i] == '?')dp[p ^ 1][j] |= (A[j] & (dp[p][j] << 1));
if((t[i] == 'N' || t[i] == '?') && j + 1 < n)dp[p ^ 1][j] |= (dp[p][j + 1] & A[j]);
if((t[i] == 'S' || t[i] == '?') && j - 1 >= 0)dp[p ^ 1][j] |= (dp[p][j - 1] & A[j]);
}
p ^= 1;
}
int ans = 0 ;
for(int i = 0;i < n;i++){
ans += dp[p][i].count();
//for(int j = 0;j < m;j++)cout<<dp[p][i][j]<<" ";
//cout<<'\n';
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
404 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
404 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
472 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
87 ms |
1076 KB |
Output is correct |
23 |
Correct |
91 ms |
860 KB |
Output is correct |
24 |
Correct |
86 ms |
1072 KB |
Output is correct |
25 |
Correct |
80 ms |
1080 KB |
Output is correct |
26 |
Correct |
83 ms |
860 KB |
Output is correct |
27 |
Correct |
127 ms |
860 KB |
Output is correct |
28 |
Correct |
130 ms |
860 KB |
Output is correct |
29 |
Correct |
126 ms |
860 KB |
Output is correct |
30 |
Correct |
130 ms |
1116 KB |
Output is correct |
31 |
Correct |
132 ms |
856 KB |
Output is correct |
32 |
Correct |
171 ms |
860 KB |
Output is correct |
33 |
Correct |
161 ms |
1072 KB |
Output is correct |
34 |
Correct |
155 ms |
856 KB |
Output is correct |
35 |
Correct |
169 ms |
860 KB |
Output is correct |
36 |
Correct |
155 ms |
860 KB |
Output is correct |