Submission #1136570

#TimeUsernameProblemLanguageResultExecution timeMemory
1136570alterioShortcut (IOI16_shortcut)C++20
0 / 100
0 ms324 KiB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define all(x) (x).begin(), (x).end()

const int mxn = 1e6 + 100;

vector<int> l, d;
ll n, c, prf[mxn], prfR[mxn];

ll get(int l, int r, bool side) {
    l = max(l, 0);
    r--;
    if (l > r) return 0;
    if (side) return prf[r] - (l == 0 ? 0 : prf[l - 1]);
    return prfR[r] - (l == 0 ? 0 : prfR[l - 1]);
}

ll minCost(int x, int y, bool side) {
    ll res = 0, mx[n];
    memset(mx, 0, sizeof(mx));
    mx[0] = d[0];
    for (int i = 1; i <= x; i++) {
        ll dist = mx[i - 1] + l[i - 1];
        mx[i] = max(dist, (ll) d[i]);
        res = max(res, dist + d[i]);
    }
    int split = x;
    for (int i = x; i <= y; i++) {
        ll goF = get(x, i, side);
        ll goA = c + get(i, y - 1, side);
        if (goF <= goA) split = i;
        else break;
    }
    for (int i = x + 1; i <= split; i++) {
        ll dist = mx[i - 1] + l[i - 1];
        mx[i] = max(dist, (ll) d[i]);
        res = max(res, dist + d[i]);
    }
    mx[y] = mx[x] + c;
    res = max(res, mx[y] + d[y]);
    for (int i = y - 1; i > split; i--) {
        ll dist = mx[i + 1] + l[i];
        mx[i] = max(dist, (ll) d[i]);
        res = max(res, dist + d[i]);
    }
    for (int i = y + 1; i < n; i++) {
        ll dist = mx[i - 1] + l[i - 1];
        mx[i] = max(dist, (ll) d[i]);
        res = max(res, dist + d[i]);
    }
    return res;
}

ll find_shortcut(int _n, vector<int> _l, vector<int> _d, int _c) {
    n = _n, l = _l, d = _d, c = _c;
    prf[0] = l[0];
    for (int i = 1; i < n - 1; i++) prf[i] = prf[i - 1] + l[i];
    reverse(all(l));
    prfR[0] = l[0];
    for (int i = 1; i < n - 1; i++) prfR[i] = prfR[i - 1] + l[i];
    reverse(all(l));
    c = 0;
    ll minAns = minCost(0, 0, 1);
    c = _c;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ll dist = get(i, j, 1);
            if (c < dist) {
                ll mx = minCost(i, j, 1);
                reverse(all(l));
                reverse(all(d));
                mx = max(mx, minCost(n - j - 1, n - i - 1, 0));
                minAns = min(minAns, mx);
                reverse(all(l));
                reverse(all(d));
            }
        }
    }
    return minAns;
}

Compilation message (stderr)

shortcut.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
shortcut_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...