Submission #1101218

#TimeUsernameProblemLanguageResultExecution timeMemory
1101218RajCircle Passing (EGOI24_circlepassing)C++11
14 / 100
2064 ms6272 KiB
#include <bits/stdc++.h> using namespace std; int n,M,Q; int v[1000001]; int stanga(int x,int y) { if(x<y) return 2*n-y+x; else return x-y; } int dreapta(int x,int y) { if(x>y) return 2*n-x+y; else return y-x; } int shc(int x, int y) { int pas1=1; int pas4=1; int pas3=1; int pas2=1; int ok=0; int k=0; int t,mn=INT_MAX; for(int i=1;i<=M;++i) { int dist=0,dist1=0,dist2=0,dist3=0; k=v[i]; int k1=0; if(k<n) k1=k+n; else k1=k-n; dist=stanga(x,k); dist1=dreapta(x,k); dist2=stanga(x,k1); dist3=dreapta(x,k1); dist=min(dist,dist1); dist1=min(dist2,dist3); if(dist>dist1) { dist=dist1; k=k1; } if(dist<mn) { mn=dist; t=k; pas1=dist; pas2=dist; } } if(t>=n) { t=t-n; pas1+=stanga(t,y)+1; pas2+=dreapta(t,y)+1; } else { t=t+n; pas1+=stanga(t,y)+1; pas2+=dreapta(t,y)+1; } return min(pas1,pas2); } int main() { cin>>n>>M>>Q; for(int i=1;i<=M;++i) { cin>>v[i]; } for(int i=1;i<=Q;++i) { int a,b; cin>>a>>b; cout<<min(shc(a,b),min(stanga(a,b),dreapta(a,b)))<<'\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int shc(int, int)':
Main.cpp:22:9: warning: unused variable 'pas4' [-Wunused-variable]
   22 |     int pas4=1;
      |         ^~~~
Main.cpp:23:9: warning: unused variable 'pas3' [-Wunused-variable]
   23 |     int pas3=1;
      |         ^~~~
Main.cpp:25:9: warning: unused variable 'ok' [-Wunused-variable]
   25 |     int ok=0;
      |         ^~
Main.cpp:69:10: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   69 |         t=t+n;
      |         ~^~~~
#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...