#include <iostream>
#include <bitset>
using namespace std;
const int R=505,M=5005;
bitset<R> acces[R];
bitset<R> dp[R][M];
int n,m,moves;
int main()
{
cin>>n>>m>>moves;
string indicatii;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
char c;
cin>>c;
if(c=='.')
{
acces[i][j]=1;
dp[i][0][j]=1;
}
}
}
cin>>indicatii;
for(int i=1; i<=moves; i++)
{
for(int k=1; k<=n; k++)
{
if(indicatii[i-1]=='E'||indicatii[i-1]=='?')
{
dp[k][i]|=(dp[k][i-1]<<1);
dp[k][i]&=acces[k];
}
if(indicatii[i-1]=='W'||indicatii[i-1]=='?')
{
dp[k][i]|=(dp[k][i-1]>>1);
dp[k][i]&=acces[k];
}
if(indicatii[i-1]=='N'||indicatii[i-1]=='?')
{
dp[k][i]|=(dp[k+1][i-1]);
dp[k][i]&=acces[k];
}
if(indicatii[i-1]=='S'||indicatii[i-1]=='?')
{
dp[k][i]|=(dp[k-1][i-1]);
dp[k][i]&=acces[k];
}
}
}
int ans=0;
for(int i=1; i<=n; i++)
ans+=dp[i][moves].count();
cout<<ans;
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... |