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[505][505];
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;
bitset<500> dp[m+10][r];
bitset<500> red[r];
for(int i=0;i<r;i++) for(int j=0;j<c;j++)
{
if(a[i][j]=='#')
{
dp[0][i][j]=0;
red[i][j]=0;
}
else
{
dp[0][i][j]=1;
red[i][j]=1;
}
}
for(int t=1;t<=m;t++)
{
char sad=s[t-1];
for(int i=0;i<r;i++)
{
if(sad=='W' || sad=='?') dp[t][i]|=(dp[t-1][i]>>1) & red[i];
if(sad=='E' || sad=='?') dp[t][i]|=(dp[t-1][i]<<1) & red[i];
if((sad=='S' || sad=='?') && i) dp[t][i]|=dp[t-1][i-1] & red[i];
if((sad=='N' || sad=='?') && i+1<r) dp[t][i]|=dp[t-1][i+1] & red[i];
/*else
{
}*/
}
}
int res=0;
for(int i=0;i<r;i++) res+=dp[m][i].count();
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... |