Submission #996590

# Submission time Handle Problem Language Result Execution time Memory
996590 2024-06-10T21:16:48 Z jklepec Sparklers (JOI17_sparklers) C++17
0 / 100
1 ms 344 KB
#include <iostream>
#include <vector>
using namespace std;

const int inf = 1e9;

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

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

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

    int 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<int, int>> 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 ((long long) v * t > inf) return true;

    vector<int> aa, bb;
    for (int i = k - 1; i >= 0; --i) {
        aa.push_back(2 * v * t - (x[i + 1] - x[i]));
    }
    for (int i = k + 1; i < n; ++i) {
        bb.push_back(2 * v * t - (x[i] - x[i - 1]));
    }
    aa.push_back(0); bb.push_back(0);

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

    int sum = 0, i = 0, j = 0;
    pair<int, int> tmp_a = {0, 0};
    pair<int, int> tmp_b = {0, 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.second - a[i].first <= sum)
            can_a = true;
        if (j < (int) b.size() && tmp_b.second - b[j].first <= sum)
            can_b = true;

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

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

    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 = 1, hi = inf;
    while (lo < hi) {
        int mid = (lo + hi) >> 1;
        if (check(mid)) {
            hi = mid;
        }
        else {
            lo = mid + 1;
        }
    }
    cout << lo << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -