답안 #996610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996610 2024-06-10T22:03:42 Z jklepec Sparklers (JOI17_sparklers) C++11
100 / 100
127 ms 8892 KB
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
const int inf = 1e9;

int n, k, t;
vector<int> x;

vector<pair<ll, ll>> make_stack(vector<ll> v) {
    int N = v.size();

    vector<int> important(N);
    vector<ll> pref(N), mx_pr(N), mn_pr(N);

    ll mx_pref = 0, current_pref = 0;
    for (int i = 0; i < N; ++i) {
        current_pref += v[i];
        pref[i] = current_pref;
        mx_pref = max(mx_pref, pref[i]);
        if (pref[i] == mx_pref) important[i] = 1;
    }
    mx_pr[N - 1] = mn_pr[N - 1] = pref[N - 1];
    for (int i = N - 2; i >= 0; --i) {
        mx_pr[i] = max(pref[i], mx_pr[i + 1]);
        mn_pr[i] = min(pref[i], mn_pr[i + 1]);
    }

    vector<pair<ll, ll>> ret = {{0, 0}};
    for (int i = 0; i < N; ++i) {
        ret.back().first = min(ret.back().first, pref[i]);
        ret.back().second = pref[i];

        if (i < N - 1) {
            if (
                important[i] ||
                (pref[i] == mx_pr[i] &&
                 mx_pr[i] > mx_pr[i + 1] &&
                 mx_pr[i] != mx_pref &&
                 ret.back().first < mn_pr[i])
            )
            ret.push_back({pref[i], pref[i]});
        }
    }
    return ret;
}

bool check(int v) {
    // if ((ll) v * t > inf) return true;
    vector<ll> aa, bb;
    for (int i = k - 1; i >= 0; --i) {
        aa.push_back(2LL * v * t - (x[i + 1] - x[i]));
    }
    for (int i = k + 1; i < n; ++i) {
        bb.push_back(2LL * v * t - (x[i] - x[i - 1]));
    }
    // K = 1 or K = N
    aa.push_back(0); bb.push_back(0);

    vector<pair<ll, ll>> a = make_stack(aa);
    vector<pair<ll, ll>> b = make_stack(bb);

    int i = 0, j = 0;
    ll sum = 0;
    ll tmp_a = 0, tmp_b = 0;
    while (i < (int) a.size() || j < (int) b.size()) {
        bool can_a = false;
        bool can_b = false;
        if (i < (int) a.size() && tmp_a - a[i].first <= sum)
            can_a = true;
        if (j < (int) b.size() && tmp_b - b[j].first <= sum)
            can_b = true;

        if (can_a == can_b) {
            if (!can_a) return false;
            if (a[i].second >= tmp_a) can_b = false;
            else if (b[j].second >= tmp_b) can_a = false;
            else {
                ll nxt_a = a[i].second - a[i].first;
                ll nxt_b = b[j].second - b[j].first;
                if (nxt_a >= nxt_b) can_b = false;
                else can_a = false;
            }
        }

        if (can_a) {
            sum += a[i].second - tmp_a;
            tmp_a = a[i++].second;
        }
        else {
            sum += b[j].second - tmp_b;
            tmp_b = b[j++].second;
        }
        // cout << sum << " " << i << " " << j << endl << endl;
    }

    return true;
}

int main() {
    cin >> n >> k >> t; --k;
    for (int i = 0; i < n; ++i) {
        int pos; cin >> pos;
        x.push_back(pos);
    }

    int lo = 0, hi = inf / t + 1;
    while (lo < hi) {
        int mid = (lo + hi) >> 1;
        if (check(mid)) {
            hi = mid;
        }
        else {
            lo = mid + 1;
        }
    }
    cout << lo << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 76 ms 4792 KB Output is correct
42 Correct 3 ms 668 KB Output is correct
43 Correct 18 ms 1588 KB Output is correct
44 Correct 115 ms 8748 KB Output is correct
45 Correct 97 ms 6344 KB Output is correct
46 Correct 99 ms 8592 KB Output is correct
47 Correct 119 ms 8596 KB Output is correct
48 Correct 96 ms 6524 KB Output is correct
49 Correct 116 ms 8872 KB Output is correct
50 Correct 99 ms 6204 KB Output is correct
51 Correct 111 ms 8572 KB Output is correct
52 Correct 122 ms 8212 KB Output is correct
53 Correct 122 ms 8812 KB Output is correct
54 Correct 127 ms 8260 KB Output is correct
55 Correct 93 ms 6348 KB Output is correct
56 Correct 96 ms 8892 KB Output is correct
57 Correct 124 ms 8484 KB Output is correct
58 Correct 100 ms 6552 KB Output is correct
59 Correct 118 ms 6608 KB Output is correct
60 Correct 124 ms 8252 KB Output is correct
61 Correct 116 ms 8116 KB Output is correct
62 Correct 99 ms 8644 KB Output is correct
63 Correct 108 ms 8052 KB Output is correct
64 Correct 95 ms 5988 KB Output is correct
65 Correct 92 ms 6480 KB Output is correct
66 Correct 116 ms 6192 KB Output is correct
67 Correct 89 ms 6776 KB Output is correct
68 Correct 104 ms 8232 KB Output is correct
69 Correct 115 ms 8220 KB Output is correct