Submission #1099358

#TimeUsernameProblemLanguageResultExecution timeMemory
1099358RajCircle Passing (EGOI24_circlepassing)C++11
0 / 100
2131 ms1014864 KiB
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <queue> #include <string.h> int n,m,q,v[50001]; std::pair<int,int> per[50001]; int cautare(int a,int b) { int cnt=0; std::queue<std::pair<int,int>> co; co.push({a,0}); while(!co.empty()) { int x=co.front().first; int t=co.front().second; if(x==b) return t; int st=x-1,dr=x+1; if(st<0) st=2*n-1; if(dr>n*2-1) dr=0; if(x==b) return cnt; else cnt++; co.pop(); co.push({st,t+1}); co.push({dr,t+1}); if(v[x]!=-1) co.push({v[x],t+1}); } } int main() { std::cin>>n>>m>>q; for(int i=0;i<=2*n-1;++i) v[i]=-1; for(int i=1;i<=m;++i) { int x; std::cin>>x; if(x>=n) { v[x]=x-n; v[x-n]=x; } else { v[x]=x+n; v[x+n]=x; } } for(int i=1;i<=q;++i) std::cin>>per[i].first>>per[i].second; for(int i=1;i<=q;++i) { int x1=per[i].first,y1=per[i].second; std::cout<<cautare(x1,y1)<<'\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int cautare(int, int)':
Main.cpp:11:36: warning: control reaches end of non-void function [-Wreturn-type]
   11 |     std::queue<std::pair<int,int>> co;
      |                                    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...