답안 #996602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996602 2024-06-10T21:53:56 Z jklepec Sparklers (JOI17_sparklers) C++17
30 / 100
2 ms 600 KB
#include <iostream>
#include <vector>
using namespace std;
#define int long long

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 = tmp_a - a[i].first;
                ll nxt_b = tmp_b - 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;
}

signed 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;
    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 600 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 600 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 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 Incorrect 1 ms 348 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 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 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 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 Incorrect 1 ms 348 KB Output isn't correct
33 Halted 0 ms 0 KB -