This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub beet-aizu/library
#ifndef call_from_test #include<bits/stdc++.h> using namespace std; #endif //BEGIN CUT HERE vector< vector<int> > gridbfs(vector<string> &st,int sy,int sx,char wall,int dir){ int h=st.size(),w=st.front().size(); vector<vector<int> > dp(h,vector<int>(w,-1)); using P = pair<int, int>; queue<P> qu; dp[sy][sx]=0; qu.emplace(sy,sx); int dy[]={1,-1,0,0,1,1,-1,-1}; int dx[]={0,0,1,-1,1,-1,1,-1}; auto in=[&](int y,int x){return 0<=y and y<h and 0<=x and x<w;}; while(!qu.empty()){ int y,x; tie(y,x)=qu.front();qu.pop(); for(int k=0;k<dir;k++){ int ny=y+dy[k],nx=x+dx[k]; if(!in(ny,nx) or st[ny][nx]==wall) continue; if(~dp[ny][nx]) continue; dp[ny][nx]=dp[y][x]+1; qu.emplace(ny,nx); } } return dp; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif
#line 1 "tools/gridbfs.cpp" #include<bits/stdc++.h> using namespace std; #endif //BEGIN CUT HERE vector< vector<int> > gridbfs(vector<string> &st,int sy,int sx,char wall,int dir){ int h=st.size(),w=st.front().size(); vector<vector<int> > dp(h,vector<int>(w,-1)); using P = pair<int, int>; queue<P> qu; dp[sy][sx]=0; qu.emplace(sy,sx); int dy[]={1,-1,0,0,1,1,-1,-1}; int dx[]={0,0,1,-1,1,-1,1,-1}; auto in=[&](int y,int x){return 0<=y and y<h and 0<=x and x<w;}; while(!qu.empty()){ int y,x; tie(y,x)=qu.front();qu.pop(); for(int k=0;k<dir;k++){ int ny=y+dy[k],nx=x+dx[k]; if(!in(ny,nx) or st[ny][nx]==wall) continue; if(~dp[ny][nx]) continue; dp[ny][nx]=dp[y][x]+1; qu.emplace(ny,nx); } } return dp; } //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif