#pragma GCC optimize ("O3,unroll-loops,Ofast")
#pragma GCC target ("avx2,bmi,bmi2,popcnt")
#include <bits/stdc++.h>
#define F first
#define pb push_back
#define sz size()
#define S second
using namespace std;
typedef long long int ll;
const int N = 505, M = 5005;
int r,c,m;
string wef,s[N];
bitset<N> dp[M][N], row[N]; // dp[m][r][c]
inline void init(){
}
inline void input(){
cin >> r >> c >> m;
for(int i=0;i<r;i++)
cin >> s[i];
cin >> wef;
}
inline void solve(){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(s[i][j] == '.'){
dp[0][i][j] = 1;
row[i][j] = 1;
}
}
}
for(int i=1;i<=m;i++){
for(int y=0;y<r;y++){
if((wef[i-1] == 'N' || wef[i-1] == '?') && y < r-1)
dp[i][y] = (dp[i][y] | (row[y] & row[y+1] & dp[i-1][y+1]));
if((wef[i-1] == 'S' || wef[i-1] == '?') && y > 0)
dp[i][y] = (dp[i][y] | (row[y] & row[y-1] & dp[i-1][y-1]));
if(wef[i-1] == 'W' || wef[i-1] == '?')
dp[i][y] = (dp[i][y] | (row[y] & (row[y] >> 1) & (dp[i-1][y] >> 1)));
if(wef[i-1] == 'E' || wef[i-1] == '?')
dp[i][y] = (dp[i][y] | (row[y] & (row[y] << 1) & (dp[i-1][y] << 1)));
}
}
/* for(int i=0;i<r;i++){
for(int j=0;j<c;j++)
cout << row[i][j];
cout << endl;
}
cout << endl;
int cnt = 0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++)
cout << dp[1][i][j];
cout << endl;
}*/
int cnt = 0;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cnt += dp[m][i][j];
cout << cnt;
}
int main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
init();
int queries = 1;
// cin >> queries;
while(queries--){
input();
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1384 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1384 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1404 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1380 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
2 ms |
1380 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1376 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1384 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1404 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1380 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
2 ms |
1380 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1376 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
97 ms |
158980 KB |
Output is correct |
23 |
Correct |
96 ms |
159028 KB |
Output is correct |
24 |
Correct |
100 ms |
159108 KB |
Output is correct |
25 |
Correct |
96 ms |
158964 KB |
Output is correct |
26 |
Correct |
95 ms |
158876 KB |
Output is correct |
27 |
Correct |
114 ms |
158944 KB |
Output is correct |
28 |
Correct |
118 ms |
159000 KB |
Output is correct |
29 |
Correct |
120 ms |
158960 KB |
Output is correct |
30 |
Correct |
115 ms |
158924 KB |
Output is correct |
31 |
Correct |
113 ms |
158992 KB |
Output is correct |
32 |
Correct |
132 ms |
159084 KB |
Output is correct |
33 |
Correct |
131 ms |
158980 KB |
Output is correct |
34 |
Correct |
142 ms |
158936 KB |
Output is correct |
35 |
Correct |
133 ms |
158996 KB |
Output is correct |
36 |
Correct |
133 ms |
158960 KB |
Output is correct |