This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |