Submission #238223

# Submission time Handle Problem Language Result Execution time Memory
238223 2020-06-10T09:30:10 Z NONAME Krov (COCI17_krov) C++17
56 / 140
1500 ms 1664 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define el '\n'
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
using namespace std;

typedef long long ll;

const int N = 1e5;

int n, h[N];
ll ans = 0;

ll f(ll x, int ps) {
    ll res = 0;

    for (int i = 0; i < n; ++i)
        res += abs(h[i] - abs(x - abs(ps - i)));

    return res;
}

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

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

    ans = -1;

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

        while (l < r) {
            ll ri = (l + r) >> 1;
            ll le = ri + 1;

            ll fri = f(ri, i);
            ll fle = f(le, i);

            if (fri < fle) r = ri;
                else l = le;
        }

        ll cur = f(l, i);

        ans = (ans == -1 ? cur : min(ans, cur));
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 94 ms 504 KB Output is correct
2 Correct 110 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 384 KB Output is correct
2 Correct 106 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 504 KB Output is correct
2 Correct 240 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 357 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 773 ms 384 KB Output is correct
2 Correct 544 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1583 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1561 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1581 ms 768 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1595 ms 1280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1584 ms 1664 KB Time limit exceeded
2 Halted 0 ms 0 KB -