# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99543 | 2019-03-05T00:45:27 Z | jhnah917 | 전봇대 (KOI13_pole) | C++14 | 41 ms | 2200 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 384 KB | Output is correct |
10 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 412 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 6 ms | 512 KB | Output is correct |
5 | Correct | 7 ms | 512 KB | Output is correct |
6 | Correct | 6 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 2080 KB | Output is correct |
2 | Correct | 27 ms | 2200 KB | Output is correct |
3 | Correct | 29 ms | 2176 KB | Output is correct |
4 | Correct | 41 ms | 2048 KB | Output is correct |
5 | Correct | 26 ms | 2176 KB | Output is correct |
6 | Correct | 29 ms | 2048 KB | Output is correct |