# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99543 | jhnah917 | 전봇대 (KOI13_pole) | C++14 | 41 ms | 2200 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<ll> v;
ll f(ll x){
ll ret = 0;
for(ll i=0; i<n; i++){
ret += abs(v[i] - (i*x));
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n; v.resize(n);
for(int i=0; i<n; i++) cin >> v[i];
ll s = 0, e = 1e9;
while(s+3 <= e){
ll t1 = (s+s+e)/3;
ll t2 = (s+e+e)/3;
if(f(t1) > f(t2)) s = t1;
else e = t2;
}
ll ans = s, mini = f(s);
for(int i=s; i<=e; i++){
ll now = f(i);
if(now < mini){
ans = i; mini = now;
}
}
cout << mini;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |