Submission #1252656

#TimeUsernameProblemLanguageResultExecution timeMemory
1252656fahmid_rngFinding Routers (IOI20_routers)C++20
100 / 100
1 ms328 KiB
#include<bits/stdc++.h> #include "routers.h" using namespace std; std::vector<int> find_routers(int l, int n, int q) { vector<int> p(n),left(n),right(n,l); //we want to modify left and right in such a way that left[i] denotes the last index, k for which use_detector(k)=i-1 & right[i] denotes the first index for which use_detector(k)=i p[0]=0; for(int i=1;i<n;++i){ left[i]=i-1; } for(int i=1;i<n;++i){ left[i]=max(p[i-1]+1,left[i]); while(right[i]-left[i]>1){ int mid=(left[i]+right[i])/2; int q=use_detector(mid); left[q+1]=mid; for(int j=i;j<=q;++j){ right[j]=mid; } } p[i]=2*left[i]-p[i-1]; //this is true because left[i]=(p[i]+p[i-1])/2 by definition i.e left[i] is exactly in the middle of p[i-1] & p[i] } return p; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...