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;
#pragma GCC optimize("Ofast")
typedef long long ll;
char mat[505][505];
bitset<505> is[505],dp[5005][505];
int main(){
std::ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int r,c,m;
cin>>r>>c>>m;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>mat[i][j];
is[i][j]=(mat[i][j]=='.');
dp[0][i][j]=is[i][j];
}
}
string s;
cin>>s;
s='a'+s;
for(int t=1;t<=m;t++){
for(int i=1;i<=r;i++){
if(s[t]=='?')
dp[t][i]=(dp[t-1][i+1]|dp[t-1][i-1]|(dp[t-1][i]<<1)|(dp[t-1][i]>>1))&is[i];
if(s[t]=='N')
dp[t][i]=dp[t-1][i+1]&is[i];
if(s[t]=='S')
dp[t][i]=dp[t-1][i-1]&is[i];
if(s[t]=='E')
dp[t][i]=(dp[t-1][i]<<1)&is[i];
if(s[t]=='W')
dp[t][i]=(dp[t-1][i]>>1)&is[i];
}
}
int cnt=0;
for(int i=1;i<=r;i++){
cnt+=dp[m][i].count();
}
cout<<cnt<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |