Submission #44864

#TimeUsernameProblemLanguageResultExecution timeMemory
44864iletavcioskiTracks in the Snow (BOI13_tracks)C++17
22.50 / 100
2157 ms1048576 KiB
#include <iostream> #include <queue> using namespace std; struct node { int x; int y; }; int n,m; char mat[4004][4004]; bool vis[4004][4004]; int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; int brojac; void bfs(queue<node> q1,queue<node> q2,int broj) { if(q1.empty()) return; brojac=broj; while(!q1.empty()) { node g=q1.front(); q1.pop(); vis[g.x][g.y]=true; for(int i=0;i<4;i++) { if(g.x+dx[i]<n&&g.x+dx[i]>=0&&g.y+dy[i]<m&&g.y+dy[i]>=0) { if(!vis[g.x+dx[i]][g.y+dy[i]]&&mat[g.x+dx[i]][g.y+dy[i]]!='.') { if(mat[g.x+dx[i]][g.y+dy[i]]!=mat[g.x][g.y]) { node g1; g1.x=g.x+dx[i]; g1.y=g.y+dy[i]; q2.push(g1); } else { node g1; g1.x=g.x+dx[i]; g1.y=g.y+dy[i]; q1.push(g1); } } } } } bfs(q2,q1,broj+1); } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin>>n>>m; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cin>>mat[i][j]; } queue<node> q1,q2; node g; g.x=0; g.y=0; q1.push(g); bfs(q1,q2,1); cout<<brojac<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...