Submission #708897

#TimeUsernameProblemLanguageResultExecution timeMemory
708897sofija6Rice Hub (IOI11_ricehub)C++14
100 / 100
23 ms3276 KiB
#include <bits/stdc++.h> #define ll long long #define MAXR 100010 using namespace std; ll pref[MAXR],a[MAXR]; ll Calc(ll L,ll R,ll pos) { ll l=L,r=R,mid,p; while (l<=r) { mid=(l+r)/2; if (a[mid]<=pos) { p=mid; l=mid+1; } else r=mid-1; } return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p); } ll Check(ll x,ll n) { ll ans=LLONG_MAX; for (ll i=1;i<=n-x+1;i++) ans=min(ans,Calc(i,i+x-1,a[(2*i+x)/2])); return ans; } int besthub(int R,int L,int X[],ll B) { for (ll i=0;i<R;i++) { pref[i+1]=pref[i]+X[i]; a[i+1]=X[i]; } int l=1,r=R,mid,ans; while (l<=r) { mid=(l+r)/2; if (Check(mid,R)<=B) { ans=mid; l=mid+1; } else r=mid-1; } return ans; }

Compilation message (stderr)

ricehub.cpp: In function 'long long int Calc(long long int, long long int, long long int)':
ricehub.cpp:20:31: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     return pos*(p-L+1)-(pref[p]-pref[L-1])+pref[R]-pref[p]-pos*(R-p);
      |                         ~~~~~~^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:48:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     return ans;
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...