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;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=507;
int d[4];
char x[4]={'S','N','W','E'};
int dx[4]={-1,1,0,0};
int dy[4]={0,0,1,-1};
int n,m,k;
bool good(int x,int y)
{
if(min(x,y)>=0&&x<n&&y<m) return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
char c;
cin>>n>>m>>k;
bitset<N*N>is,A;
d[0]=-m;
d[1]=m;
d[2]=1;
d[3]=-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>c;
if(c=='.') A[i*m+j]=1;
}
}
is=A;
while(k--)
{
cin>>c;
bitset<N*N>nis;
if(c=='N') nis=is>>m;
if(c=='S') nis=is<<m;
if(c=='E') nis=is<<1;
if(c=='W') nis=is>>1;
if(c=='?') nis=(is>>m)|(is<<m)|(is>>1)|(is<<1);
for(int i=0;i<n;i++)
{
nis[i*m]=0;
nis[i*m+m-1]=0;
for(int j=0;j<4;j++)
{
if(c==x[j]||c=='?')
{
if(good(i+dx[j],0+dy[j])&&is[i*m+d[j]]) nis[i*m]=1;
if(good(i+dx[j],m-1+dy[j])&&is[i*m+m-1+d[j]]) nis[i*m+m-1]=1;
}
}
}
is=nis;
is&=A;
}
cout<<is.count();
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... |