제출 #747069

#제출 시각아이디문제언어결과실행 시간메모리
747069LCJLYTracks in the Snow (BOI13_tracks)C++14
6.67 / 100
533 ms126800 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int>pii; int32_t main(){ //ios::sync_with_stdio(0); //cin.tie(0); int n,m; cin >> n >> m; string arr[n]; for(int x=0;x<n;x++){ cin >> arr[x]; } queue<pii>q; queue<pii>q2; int counter=0; bool visited[n+5][m+5]; memset(visited,0,sizeof(visited)); bool amos=true; //true is R, false is F if(arr[0][0]=='F') amos=false; if(amos){ q.push({0,0}); visited[0][0]=true; } else{ q2.push({0,0}); visited[0][0]=true; } pii dir[4]={ {1,0}, {-1,0}, {0,1}, {0,-1}, }; while(!q.empty()||!q2.empty()){ if(amos){ while(!q.empty()){ pii cur=q.front(); q.pop(); for(auto it:dir){ int newx=cur.first+it.first; int newy=cur.second+it.second; if(newx<0||newy<0||newy>=n||newy>=m) continue; if(visited[newx][newy]) continue; if(arr[newx][newy]=='.') continue; visited[newx][newy]=true; if(arr[newx][newy]=='R'){ q.push({newx,newy}); } else{ q2.push({newx,newy}); } } } amos=false; } else{ while(!q2.empty()){ pii cur=q2.front(); //cout << cur.first << " " << cur.second << " visit\n"; q2.pop(); for(auto it:dir){ int newx=cur.first+it.first; int newy=cur.second+it.second; if(newx<0||newy<0||newy>=n||newy>=m) continue; if(visited[newx][newy]) continue; if(arr[newx][newy]=='.') continue; visited[newx][newy]=true; if(arr[newx][newy]=='R'){ q.push({newx,newy}); } else{ q2.push({newx,newy}); } } } amos=true; } counter++; //cout << counter << "\n"; } cout << counter; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...