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;
int r,c,m;
char a[105][105];
string s;
bool dp[105][105][105];
int main()
{
ios_base::sync_with_stdio(false);
cin>>r>>c>>m;
for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin>>a[i][j];
cin>>s;
memset(dp, false, sizeof(dp));
for(int i=0;i<r;i++) for(int j=0;j<c;j++) if(a[i][j]=='.') dp[0][i][j]=true;
for(int t=1;t<=m;t++)
{
char sad=s[t-1];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(a[i][j]=='#') continue;
if((sad=='N' || sad=='?') && i+1<r) dp[t][i][j]=dp[t][i][j] || dp[t-1][i+1][j];
if((sad=='S' || sad=='?') && i-1>=0) dp[t][i][j]=dp[t][i][j] || dp[t-1][i-1][j];
if((sad=='W' || sad=='?') && j+1<c) dp[t][i][j]=dp[t][i][j] || dp[t-1][i][j+1];
if((sad=='E' || sad=='?') && j-1>=0) dp[t][i][j]=dp[t][i][j] || dp[t-1][i][j-1];
}
}
}
int res=0;
for(int i=0;i<r;i++) for(int j=0;j<c;j++) res+=(dp[m][i][j]>0);
cout<<res<<endl;
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... |