Submission #661338

# Submission time Handle Problem Language Result Execution time Memory
661338 2022-11-25T15:04:55 Z bebra Krov (COCI17_krov) C++17
70 / 140
1500 ms 1612 KB
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x << ": " << x << endl;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    int max_value = 0;
    for (auto& x : a) {
        cin >> x;
        max_value = max(max_value, x);
    }
    auto f = [&](int idx, int value) {
        long long res = 0;
        for (int i = 0; i < n; ++i) {
            res += abs(a[i] - (value - abs(i - idx)));
        }
        return res;
    };
    long long ans = 1e18;
    for (int i = 0; i < n; ++i) {
        int l = max(i + 1, n - i);
        int r = 1e9 + 5;
        while (l != r - 1) {
            int m = (l + r) / 2;
            if (f(i, m) > f(i, m + 1)) {
                l = m;
            } else {
                r = m;
            }
        }
        ans = min(ans, min(f(i, l), f(i, r)));
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 78 ms 308 KB Output is correct
2 Correct 94 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 328 KB Output is correct
2 Correct 101 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 320 KB Output is correct
2 Correct 213 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 340 KB Output is correct
2 Correct 392 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 708 ms 340 KB Output is correct
2 Correct 484 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1579 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1587 ms 468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1583 ms 712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1567 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1563 ms 1612 KB Time limit exceeded
2 Halted 0 ms 0 KB -