#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){
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) used[i][j]=0;
queue<pair<int,pair<int,int>>>q;
q.push({x,{y,0}});
used[x][y]=1;
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}});
used[tx][ty]=1;
++ok;
}
}
//if(!ok) return 0;
}return 0;
}
void solve(){
cin>>n>>m>>k;
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
cin>>c[i][j];
}
}
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:30:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if(yy==s.size())return 1;
| ~~^~~~~~~~~~
nautilus.cpp:49:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if(tx<=n && ty<=m && min(tx,ty)>=1 && c[tx][ty]=='.' && yy<s.size()){
| ~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
768 KB |
Output is correct |
2 |
Incorrect |
12 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |