답안 #8094

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
8094 2014-08-29T16:31:17 Z gs14004 전봇대 (KOI13_pole) C++
100 / 100
56 ms 2648 KB
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long lint;

struct pole{lint a,i;}d[100005];
int cmp(pole a, pole b){return a.a * b.i < b.a * a.i;}

lint n;
lint trial(lint piv){
    lint res = 0;
    for (int i=0; i<n; i++) {
        res += max(d[i].a - piv * d[i].i, piv * d[i].i - d[i].a);
    }
    return res;
}

int main(){
    scanf("%lld",&n);
    for (int i=0; i<n; i++) {
        scanf("%lld",&d[i].a);
        d[i].i = i;
    }
    sort(d,d+n,cmp);
    int piv;
    lint cum = 0;
    for (piv = 0; piv < n; piv++) {
        cum += d[piv].i;
        if(cum > n * (n-1) / 4) break;
    }
    lint that = d[piv].a / d[piv].i;
    printf("%lld",min(min(trial(that-1),trial(that)),trial(that+1)));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 0 ms 2648 KB Output is correct
3 Correct 0 ms 2648 KB Output is correct
4 Correct 0 ms 2648 KB Output is correct
5 Correct 0 ms 2648 KB Output is correct
6 Correct 0 ms 2648 KB Output is correct
7 Correct 0 ms 2648 KB Output is correct
8 Correct 0 ms 2648 KB Output is correct
9 Correct 0 ms 2648 KB Output is correct
10 Correct 0 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 0 ms 2648 KB Output is correct
3 Correct 0 ms 2648 KB Output is correct
4 Correct 0 ms 2648 KB Output is correct
5 Correct 0 ms 2648 KB Output is correct
6 Correct 0 ms 2648 KB Output is correct
7 Correct 0 ms 2648 KB Output is correct
8 Correct 0 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2648 KB Output is correct
2 Correct 0 ms 2648 KB Output is correct
3 Correct 4 ms 2648 KB Output is correct
4 Correct 0 ms 2648 KB Output is correct
5 Correct 4 ms 2648 KB Output is correct
6 Correct 4 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2648 KB Output is correct
2 Correct 56 ms 2648 KB Output is correct
3 Correct 40 ms 2648 KB Output is correct
4 Correct 52 ms 2648 KB Output is correct
5 Correct 48 ms 2648 KB Output is correct
6 Correct 56 ms 2648 KB Output is correct