Submission #835906

#TimeUsernameProblemLanguageResultExecution timeMemory
835906BT21tataGap (APIO16_gap)C++17
73.91 / 100
56 ms2232 KiB
#include "gap.h" #include<bits/stdc++.h> typedef long long ll; #define pb push_back using namespace std; vector<ll>v; ll mn, mx; long long findGap(int T, int n) { if(T==1) { ll l=0, r=1e18, ret=0; while(v.size()<n) { MinMax(l, r, &mn, &mx); v.pb(mn); v.pb(mx); l=mn+1; r=mx-1; } sort(v.begin(), v.end()); for(int i=1; i<(int)v.size(); i++) ret=max(ret, v[i]-v[i-1]); return ret; } MinMax(0, 1e18, &mn, &mx); ll gap=(mx-mn-1)/(n-1)+1; ll l=mn, r=mx, curl=l, curr=l+gap-1, ans=gap; //cout<<curr<<endl; while(curr-gap<=r) { //cout<<curl<<' '<<curr<<" "<<ans<<endl; MinMax(curl+1, curr, &mn, &mx); if(mx==-1) mn=mx=curl; else mn=curl; if(mn!=mx and mx-mn<=gap) curl=mx, curr=curl+gap-1; else if(mn==mx) curl=mn, curr+=gap; else { MinMax(curr-gap+1, curr, &mn, &mx); if(mn==mx) ans=max(ans, mx-curl); else ans=max(ans, mn-curl); curl=mx, curr=curl+gap-1; } } return ans; } /* 11 5 7 8 100 130 190 200 201 203 1000 2004 */

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:15:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |   while(v.size()<n)
      |         ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...