Submission #125540

#TimeUsernameProblemLanguageResultExecution timeMemory
125540The_WolfpackNautilus (BOI19_nautilus)C++14
100 / 100
356 ms157944 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...