#include <bits/stdc++.h>
using namespace std;
int di[4]={1,-1,0,0};
int dj[4]={0,0,-1,1};
int main()
{
ios_base::sync_with_stdio(false);
int r,c,mx;
string m;
cin>>r>>c>>mx;
char mat[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>mat[i][j];
}
}
cin>>m;
int ans=0;
queue<int>Q;
bool vis[r][c];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
memset(vis,0,sizeof vis);
if(mat[i][j]=='.')///"";
{
Q.push(i);
Q.push(j);
Q.push(0);
while(!Q.empty())
{
int ti=Q.front();Q.pop();
int tj=Q.front();Q.pop();
int k=Q.front();Q.pop();
if(k==m.size())
{
ans++;
}
else
{
if(m[k]=='?')
{
for(int idx=0;idx<4;idx++)
{
int ci=ti+di[idx];
int cj=tj+dj[idx];
if(ci<0||cj<0||ci>=r||cj>=c)continue;
if(mat[ci][cj]=='#')continue;
if(vis[ci][cj])continue;
Q.push(ci);
Q.push(cj);
Q.push(k+1);
vis[ci][cj]=true;
}
}
else
{
int ci=ti;
int cj=tj;
if(m[k]=='N')
{
ci--;
}
else if(m[k]=='S')
{
ci++;
}
else if(m[k]=='W')
{
cj--;
}
else
{
cj++;
}
if(ci<0||cj<0||ci>=r||cj>=c)continue;
if(mat[ci][cj]=='#')continue;
if(vis[ci][cj])continue;
Q.push(ci);
Q.push(cj);
Q.push(k+1);
vis[ci][cj]=true;
}
}
}
while(!Q.empty())
{
Q.pop();
}
}
}
}
cout<<ans<<endl;
return 0;
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(k==m.size())
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |