Submission #236735

# Submission time Handle Problem Language Result Execution time Memory
236735 2020-06-03T07:25:58 Z VEGAnn Krov (COCI17_krov) C++14
70 / 140
1500 ms 2048 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)));

    ans = min(ans, cur);

    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 163 ms 384 KB Output is correct
2 Correct 199 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 504 KB Output is correct
2 Correct 194 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 504 KB Output is correct
2 Correct 462 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 504 KB Output is correct
2 Correct 803 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 504 KB Output is correct
2 Correct 989 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1590 ms 640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1594 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1584 ms 1536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1592 ms 2048 KB Time limit exceeded
2 Halted 0 ms 0 KB -