#include<iostream>
#include<queue>
#include<tuple>
using namespace std;
char a[510][510];
string s;
int poz[250];
int m,r,c;
pair<int,int>p[4]={{-1,0},{0,1},{1,0},{0,-1}};
int czy_odw[510][510];
queue< pair< pair<int,int>,int> >q;
int beefes(){
pair<int,int>xy;
int wyn=0;
int kt;
while(!q.empty()){
tie(xy,kt)=q.front();
q.pop();
// cout<<kt<<' ';
if(kt==m){
wyn++;
// a[xy.first][xy.second]='X';
continue;
}
if(s[kt]=='?'){
for(int i=0;i<4;i++){
if(czy_odw[xy.first+p[i].first][xy.second+p[i].second]<kt+1&&a[xy.first+p[i].first][xy.second+p[i].second]=='.'){
q.push({{xy.first+p[i].first,xy.second+p[i].second},kt+1});
czy_odw[xy.first+p[i].first][xy.second+p[i].second]=kt+1;
}
}
}
else{
// cout<<kt<<' '<<xy.first<<' '<<xy.second<<'\n';
if(czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]<kt+1&&a[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=='.'){
// cout<<kt<<' '<<xy.first<<' '<<xy.second<<'\n';
q.push({{xy.first+p[poz[s[kt]]].first,xy.second+p[poz[s[kt]]].second},kt+1});
czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=kt+1;
}
}
}
/*for(int i=0;i<=r+1;i++){
for(int j=0;j<=c+1;j++)cout<<a[i][j];
cout<<'\n';
}*/
return wyn;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>r>>c>>m;
poz['N']=0;
poz['E']=1;
poz['S']=2;
poz['W']=3;
for(int i=0;i<=r+1;i++){
for(int j=0;j<=c+1;j++){
if(i>0&&i<=r&&j>0&&j<=c)cin>>a[i][j];
else a[i][j]='#';
if(a[i][j]=='.')q.push({{i,j},0});
}
}
cin>>s;
cout<<beefes();
return 0;
}
Compilation message
nautilus.cpp: In function 'int beefes()':
nautilus.cpp:35:35: warning: array subscript has type 'char' [-Wchar-subscripts]
35 | if(czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]<kt+1&&a[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=='.'){
| ^
nautilus.cpp:35:66: warning: array subscript has type 'char' [-Wchar-subscripts]
35 | if(czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]<kt+1&&a[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=='.'){
| ^
nautilus.cpp:35:105: warning: array subscript has type 'char' [-Wchar-subscripts]
35 | if(czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]<kt+1&&a[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=='.'){
| ^
nautilus.cpp:35:136: warning: array subscript has type 'char' [-Wchar-subscripts]
35 | if(czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]<kt+1&&a[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=='.'){
| ^
nautilus.cpp:37:34: warning: array subscript has type 'char' [-Wchar-subscripts]
37 | q.push({{xy.first+p[poz[s[kt]]].first,xy.second+p[poz[s[kt]]].second},kt+1});
| ^
nautilus.cpp:37:64: warning: array subscript has type 'char' [-Wchar-subscripts]
37 | q.push({{xy.first+p[poz[s[kt]]].first,xy.second+p[poz[s[kt]]].second},kt+1});
| ^
nautilus.cpp:38:33: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=kt+1;
| ^
nautilus.cpp:38:64: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | czy_odw[xy.first+p[poz[s[kt]]].first][xy.second+p[poz[s[kt]]].second]=kt+1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
9 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
604 KB |
Output is correct |
13 |
Correct |
14 ms |
600 KB |
Output is correct |
14 |
Correct |
10 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
440 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
16 ms |
732 KB |
Output is correct |
19 |
Correct |
7 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
9 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
604 KB |
Output is correct |
13 |
Correct |
14 ms |
600 KB |
Output is correct |
14 |
Correct |
10 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
440 KB |
Output is correct |
17 |
Correct |
10 ms |
604 KB |
Output is correct |
18 |
Correct |
16 ms |
732 KB |
Output is correct |
19 |
Correct |
7 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Execution timed out |
1063 ms |
4956 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |