답안 #7422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
7422 2014-08-05T05:47:28 Z gs13068 전봇대 (KOI13_pole) C++
100 / 100
32 ms 1476 KB
#include<cstdio>
#include<algorithm>

int a[100000],n;

long long calc(int x)
{
  int i;
  long long r=0;
  for(i=0;i<n;i++)r+=std::abs(a[i]-a[0]-1LL*i*x);
  return r;
}

int main()
{
  int l,r,mid;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  l=1;r=1000000000;
  while(l<r)
  {
    mid=(l+r)/2;
    if(calc(mid)<calc(mid+1))r=mid;
    else l=mid+1;
  }
  printf("%lld",calc(l));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1476 KB Output is correct
2 Correct 0 ms 1476 KB Output is correct
3 Correct 0 ms 1476 KB Output is correct
4 Correct 0 ms 1476 KB Output is correct
5 Correct 0 ms 1476 KB Output is correct
6 Correct 0 ms 1476 KB Output is correct
7 Correct 0 ms 1476 KB Output is correct
8 Correct 0 ms 1476 KB Output is correct
9 Correct 0 ms 1476 KB Output is correct
10 Correct 0 ms 1476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1476 KB Output is correct
2 Correct 0 ms 1476 KB Output is correct
3 Correct 0 ms 1476 KB Output is correct
4 Correct 0 ms 1476 KB Output is correct
5 Correct 0 ms 1476 KB Output is correct
6 Correct 0 ms 1476 KB Output is correct
7 Correct 0 ms 1476 KB Output is correct
8 Correct 0 ms 1476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1476 KB Output is correct
2 Correct 0 ms 1476 KB Output is correct
3 Correct 4 ms 1476 KB Output is correct
4 Correct 4 ms 1476 KB Output is correct
5 Correct 4 ms 1476 KB Output is correct
6 Correct 4 ms 1476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1476 KB Output is correct
2 Correct 24 ms 1476 KB Output is correct
3 Correct 28 ms 1476 KB Output is correct
4 Correct 24 ms 1476 KB Output is correct
5 Correct 20 ms 1476 KB Output is correct
6 Correct 28 ms 1476 KB Output is correct