답안 #14677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14677 2015-06-03T01:36:42 Z Fakeable 전봇대 (KOI13_pole) C++
100 / 100
32 ms 1980 KB
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,t;
vector<int> v;
inline ll Abs(ll x) {
    return x>0?x:-x;
}
ll calc(ll p) {
    ll ret = 0;
    for(int i=1;i<n;i++) ret += Abs(v[i]-i*p);
    return ret;
}
int search(int front,int rear) {
    if(front == rear) return front;
    int mid = (front + rear) / 2;
    ll first = calc(mid);
    ll second = calc(mid+1);
    if(first < second) return search(front, mid);
    return search(mid+1, rear);
}
int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&t);
        v.push_back(t);
    }
    int M = 0;
    for(int i=1;i<n;i++) M = max(M, v[i]/i+1);
    int dydx = search(1,M);
    ll ans = 0;
    for(int i=1;i<n;i++) ans += Abs(v[i]-i*dydx);
    printf("%lld\n",ans);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 0 ms 1208 KB Output is correct
5 Correct 0 ms 1208 KB Output is correct
6 Correct 0 ms 1208 KB Output is correct
7 Correct 0 ms 1208 KB Output is correct
8 Correct 0 ms 1208 KB Output is correct
9 Correct 0 ms 1208 KB Output is correct
10 Correct 0 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 0 ms 1208 KB Output is correct
5 Correct 0 ms 1208 KB Output is correct
6 Correct 0 ms 1208 KB Output is correct
7 Correct 0 ms 1208 KB Output is correct
8 Correct 0 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 3 ms 1208 KB Output is correct
4 Correct 0 ms 1208 KB Output is correct
5 Correct 0 ms 1208 KB Output is correct
6 Correct 0 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1980 KB Output is correct
2 Correct 31 ms 1980 KB Output is correct
3 Correct 31 ms 1980 KB Output is correct
4 Correct 20 ms 1980 KB Output is correct
5 Correct 32 ms 1980 KB Output is correct
6 Correct 19 ms 1980 KB Output is correct