답안 #661343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661343 2022-11-25T15:17:09 Z bebra Krov (COCI17_krov) C++17
70 / 140
1500 ms 732 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 g = [&](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;
    };
    auto f = [&](int i){
        int l = max(i + 1, n - i);
        int r = 1e9 + 5;
        while (l != r - 1) {
            int m = (l + r) / 2;
            if (g(i, m) > g(i, m + 1)) {
                l = m;
            } else {
                r = m;
            }
        }
        long long curr_min = min(g(i, l), g(i, r));
        return curr_min;
    };
    int l = 0;
    int r = n;
    while (l != r - 1) {
        int m = (l + r) / 2;
        if (f(m) > f(m + 1)) {
            l = m;
        } else {
            r = m;
        }
    }
    long long ans = 1e18;
    for (int i = max(0, l - 2000); i < min(n, r + 2000); ++i) {
        ans = min(ans, f(i));
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 212 KB Output is correct
2 Correct 101 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 316 KB Output is correct
2 Correct 98 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 316 KB Output is correct
2 Correct 223 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 348 KB Output is correct
2 Correct 363 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 594 ms 340 KB Output is correct
2 Correct 435 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1546 ms 368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1572 ms 468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1592 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1574 ms 732 KB Time limit exceeded
2 Halted 0 ms 0 KB -