#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;
const ll mod=1e9+7;
const ll inf=mod;
const int N=5e5+4;
int X[]={0,0,1,-1};
int Y[]={1,-1,0,0};
int n,m,k,used[600][600];
char c[600][600];
string s;
int bfs(int x,int y){
queue<pair<int,pair<int,int>>>q;
q.push({x,{y,0}});
while(!q.empty()){
int x=q.front().first,y=q.front().second.first,yy=q.front().second.second;
q.pop();
if(yy==s.size())return 1;
int l=0,r=4;
if(s[yy]=='E') r=1;
if(s[yy]=='W') {
l=1;
r=2;
}
if(s[yy]=='S') {
l=2;
r=3;
}
if(s[yy]=='N') {
l=3;
r=4;
}
int ok=0;
for(int i=l; i<r; ++i){
int tx=x+X[i];
int ty=y+Y[i];
if(tx<=n && ty<=m && min(tx,ty)>=1 && c[tx][ty]=='.' && yy<s.size()){
q.push({tx,{ty,yy+1}});
++ok;
}
}
//if(!ok) return 0;
}
return 0;
}
void solve(){
cin>>n>>m>>k;
for(int i=1; i<=n; ++i){
string cc;
cin>>cc;
for(int j=1; j<=m; ++j){
c[i][j]=cc[j-1];
}
}
cin>>s;
int mx=0;
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
mx+=bfs(i,j);
}
}
cout<<mx<<endl;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt=1;
// cin>>tt;
while(tt--) {
solve();
}
}
Compilation message
nautilus.cpp: In function 'int bfs(int, int)':
nautilus.cpp:28:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(yy==s.size())return 1;
| ~~^~~~~~~~~~
nautilus.cpp:47:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(tx<=n && ty<=m && min(tx,ty)>=1 && c[tx][ty]=='.' && yy<s.size()){
| ~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
524 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
524 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
524 KB |
Output is correct |
2 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |