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 ll long long
#define lld long long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=5e5+100;
const int mod=1e9+7;
const int K=500;
const ll inf=1e18+1337;
const int dx[]={-1, 0, 0, 1};
const int dy[]={0, -1, 1, 0};
char c[K+10][K+10];
ll n,m,k,ans=0;
string s;
void sol(ll it, ll x, ll y)
{
if(it==s.size())
{
c[x][y]='X';
return;
}
if(s[it]=='?')
{
for(int i=0;i<4;i++)
{
ll xx=x+dx[i],yy=y+dy[i];
if(xx<1 || yy<1 || xx>n || yy>m) continue;
if(c[xx][yy]!='#') sol(it+1,xx,yy);
}
}
else
{
if(s[it]=='W' && y-1>=1 && c[x][y-1]!='#') sol(it+1,x,y-1);
if(s[it]=='N' && x-1>=1 && c[x-1][y]!='#') sol(it+1,x-1,y);
if(s[it]=='E' && y+1<=m && c[x][y+1]!='#') sol(it+1,x,y+1);
if(s[it]=='S' && x+1<=n && c[x+1][y]!='#') sol(it+1,x+1,y);
}
}
int main()
{
IShowSpeed
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>c[i][j];
cin>>s;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(c[i][j]!='#')
sol(0,i,j);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(c[i][j]=='X')
ans++;
cout<<ans;
}
Compilation message (stderr)
nautilus.cpp: In function 'void sol(long long int, long long int, long long int)':
nautilus.cpp:23:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(it==s.size())
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |