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;
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |