This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
bitset<maxn> G[maxn], dp[maxn][2];
int n, m, Q;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> Q;
for(int i = 1; i <= n; ++i){
for(int j = 0; j < m; ++j){
char c; cin >> c;
G[i][j] = (c == '.');
}
dp[i][0] = G[i];
}
string s; cin >> s;
for(int i = 0; i < Q; ++i){
for(int j = 1; j <= n; ++j){
if(s[i] == '?')dp[j][(i+1)&1] = dp[j+1][i&1] | dp[j-1][i&1] | (dp[j][i&1]<<1) | (dp[j][i&1] >> 1);
if(s[i] == 'N')dp[j][(i+1)&1] = dp[j+1][i&1];
if(s[i] == 'E')dp[j][(i+1)&1] = dp[j][i&1]<<1;
if(s[i] == 'W')dp[j][(i+1)&1] = dp[j][i&1]>>1;
if(s[i] == 'S')dp[j][(i+1)&1] = dp[j-1][i&1];
dp[j][(i+1)&1]&=G[j];
}
}
int ans = 0;
for(int i = 1; i <= n; ++i){
ans+=dp[i][Q&1].count();
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |