Submission #708856

#TimeUsernameProblemLanguageResultExecution timeMemory
708856sofija6Rice Hub (IOI11_ricehub)C++14
17 / 100
52 ms3404 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++) { ll pos=(pref[i+x-1]-pref[i-1])/x; if (pos>=a[i]) ans=min(ans,Calc(i,i+x-1,pos)); if (pos+1<=a[i+x-1]) ans=min(ans,Calc(i,i+x-1,pos+1)); } 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:54:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     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...