답안 #1054509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054509 2024-08-12T10:21:43 Z unnick Safety (NOI18_safety) C++14
9 / 100
2000 ms 262144 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;

int main() {
    int n, h;
    cin >> n >> h;
    if (h == 0) {
        vector<int> a;
        ll sum = 0;

        for (int i = 0; i < n; i++) {
            int tmp;
            cin >> tmp;
            a.push_back(tmp);
        }

        sort(a.begin(), a.end());
        int p = a[a.size() / 2];

        for (auto v : a) {
            sum += abs(v-p);
        }

        cout << sum << "\n";
        return 0;
    }

    vector<int> a(n);

    int q = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        q = max(q, a[i]);
    }
    q++;

    vector<ll> aa(q);
    vector<ll> ab(q);

    for (int i = 0; i < q; i++) {
        aa[i] = abs(a[0]-i);
    }

    for (int j = 1; j < n; j++) {
        for (int i = 0; i < q; i++) {
            ll tmp = 0x7FFFFFFFFFFFFFFFLL;
            for (int o = -h; o <= h; o++) {
                if (i+o >= 0 && i+o < q) tmp = min(tmp, aa[i+o]);
            }
            ab[i] = tmp + abs(i - a[j]);
        }
        aa.swap(ab);
    }

    ll sol = 0x7FFFFFFFFFFFFFFFLL;

    for (int i = 0; i < q; i++) sol = min(sol, aa[i]);
    cout << sol << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2504 KB Output is correct
2 Correct 47 ms 2516 KB Output is correct
3 Correct 50 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2099 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -