Submission #16292

#TimeUsernameProblemLanguageResultExecution timeMemory
16292khsoo01전봇대 (KOI13_pole)C++98
100 / 100
38 ms1864 KiB
#include<cstdio> #define abs(X)(X>0?X:-(X)) #define ll long long ll n,a[100005],t,p,ans,mn=1e18; void binSrch(ll x,ll y) { if(x==y)return; ll pivot=(x+y)/2,d=0,q=0; for(ll i=0;i<n;i++) { if(i*pivot<a[i])d+=i; if(i*pivot>a[i])d-=i; q+=abs(pivot*i-a[i]); } if(q<mn)mn=q; if(d<0)binSrch(x,pivot); if(d>0)binSrch(pivot+1,y); } int main() { ll i; scanf("%d",&n); scanf("%d",&a[0]); t=a[0]; a[0]=0; for(i=1;i<n;i++) { scanf("%d",&a[i]); a[i]-=t; } binSrch(0,1000000001); printf("%lld",mn); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...