Submission #236736

# Submission time Handle Problem Language Result Execution time Memory
236736 2020-06-03T07:26:45 Z VEGAnn Krov (COCI17_krov) C++14
70 / 140
1500 ms 1152 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define ft first
#define sd second
using namespace std;
typedef long long ll;
const int N = 100100;
const int oo = int(2e9);
const ll OO = 1e18;
const int md = int(1e9) + 7;
int n;
ll x[N], ans = OO;

ll get(int id, ll ht){
    ll cur = 0;

    for (int i = 0; i < n; i++)
        cur += abs(x[i] - (ht - abs(i - id)));

    return cur;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> x[i];

    for (int i = 0; i < n; i++){
        ll l = max(i + 1, n - i), r = ll(1e9);

        while (l + 5 < r){
            ll md1 = l + (r - l) / 3;
            ll md2 = r - (r - l) / 3;

            if (get(i, md1) < get(i, md2))
                r = md2;
            else l = md1;
        }

        for (ll j = l; j <= r; j++)
            ans = min(ans, get(i, j));
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 168 ms 504 KB Output is correct
2 Correct 200 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 384 KB Output is correct
2 Correct 204 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 426 ms 504 KB Output is correct
2 Correct 457 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 731 ms 400 KB Output is correct
2 Correct 795 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 384 KB Output is correct
2 Correct 1002 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1579 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1583 ms 640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1590 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 1152 KB Time limit exceeded
2 Halted 0 ms 0 KB -