Submission #99543

#TimeUsernameProblemLanguageResultExecution timeMemory
99543jhnah917전봇대 (KOI13_pole)C++14
100 / 100
41 ms2200 KiB
#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)

pole.cpp: In function 'int main()':
pole.cpp:28:5: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
  ll ans = s, mini = f(s);
     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...