답안 #16292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16292 2015-08-20T01:20:25 Z khsoo01 전봇대 (KOI13_pole) C++
100 / 100
38 ms 1864 KB
#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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1864 KB Output is correct
2 Correct 0 ms 1864 KB Output is correct
3 Correct 0 ms 1864 KB Output is correct
4 Correct 0 ms 1864 KB Output is correct
5 Correct 0 ms 1864 KB Output is correct
6 Correct 0 ms 1864 KB Output is correct
7 Correct 0 ms 1864 KB Output is correct
8 Correct 0 ms 1864 KB Output is correct
9 Correct 0 ms 1864 KB Output is correct
10 Correct 0 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1864 KB Output is correct
2 Correct 0 ms 1864 KB Output is correct
3 Correct 0 ms 1864 KB Output is correct
4 Correct 0 ms 1864 KB Output is correct
5 Correct 0 ms 1864 KB Output is correct
6 Correct 0 ms 1864 KB Output is correct
7 Correct 0 ms 1864 KB Output is correct
8 Correct 0 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1864 KB Output is correct
2 Correct 0 ms 1864 KB Output is correct
3 Correct 0 ms 1864 KB Output is correct
4 Correct 4 ms 1864 KB Output is correct
5 Correct 5 ms 1864 KB Output is correct
6 Correct 2 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 1864 KB Output is correct
2 Correct 29 ms 1864 KB Output is correct
3 Correct 31 ms 1864 KB Output is correct
4 Correct 35 ms 1864 KB Output is correct
5 Correct 26 ms 1864 KB Output is correct
6 Correct 32 ms 1864 KB Output is correct