#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()) continue;
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]=='.'){
q.push({tx,{ty,yy+1}});
++ok;
}
else{
return 0;
}
}
//if(!ok) return 0;
}
return 1;
}
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){
if(c[i][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()) continue;
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
1036 ms |
3672 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Execution timed out |
1036 ms |
3672 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |