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>
#pragma GCC optimize("Ofast")
using namespace std;
int r, c, n;
string str;
int mat[501][501];
int dp[2][501][501];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>r>>c>>n;
memset(dp, 0, sizeof dp);
memset(mat, 0, sizeof mat);
for(int i = 0; i < r; i++){
string s;
cin>>s;
for(int j = 0; j < c; j++){
if(s[j] == '.'){
mat[i][j] = 1;
dp[0][i][j] = 1;
}
}
}
cin>>str;
for(int step = 1; step <= n; step++){
int sega = step & 1, pret = (step-1) & 1;
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
dp[sega][i][j] = 0;
}
}
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(mat[i][j] == 1){
if((str[step-1] == 'E' || str[step-1] == '?') && dp[pret][i][j-1] == 1 && j > 0)
dp[sega][i][j] = 1;
if((str[step-1] == 'W' || str[step-1] == '?') && dp[pret][i][j+1] == 1 && j + 1 < c)
dp[sega][i][j] = 1;
if((str[step-1] == 'N' || str[step-1] == '?') && i < r-1 && dp[pret][i+1][j] == 1)
dp[sega][i][j] = 1;
if((str[step-1]=='S' || str[step-1] == '?') && i > 0 && dp[pret][i-1][j]==1)
dp[sega][i][j] = 1;
}
else continue;
}
}
}
long long ans = 0;
int sega = n & 1;
for(int i = 0; i < r; i++){
for(int j = 0; j < c;j ++){
ans += dp[sega][i][j];
}
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |