답안 #784931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784931 2023-07-16T19:31:05 Z GusterGoose27 Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 212 KB
#include "shortcut.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pli;

const int MAXN = 1e5+5;
const int MAXM = 1e9+5;
ll pre[MAXN];
ll max_dist[MAXN];
pli elems1[MAXN];
pli elems2[MAXN];
int n;

ll sum(int l, int r) {
    return pre[r]-pre[l];
}

bool makeable(ll cur, vector<int> d, int c) {
    ll mx1 = -(ll)MAXN*MAXM;
    ll mx2 = -(ll)MAXN*MAXM;
    int j = 0;
    priority_queue<int> left;
    priority_queue<int, vector<int>, greater<int>> right;
    ll lval = -(ll)MAXN*MAXM;
    ll rval = (ll)MAXN*MAXM;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && elems2[j].first > cur+elems1[i].first) {
            int v = elems2[j].second;
            if (j % 2 == 0) {
                if (lval <= pre[v] && rval >= pre[v]) {
                    left.push(lval);
                    right.push(rval);
                    lval = rval = pre[v];
                    sum += d[v];
                }
                else {
                    if (pre[v] < lval) {
                        left.push(pre[v]);
                        right.push(rval);
                        rval = lval;
                        sum += d[v]+lval-pre[v];
                    }
                    else {
                        left.push(lval);
                        right.push(pre[v]);
                        lval = rval;
                        sum += d[v]+pre[v]-rval;
                    }
                }
            }
            else {
                if (pre[v] < lval) {
                    sum += d[v]+lval-pre[v];
                    left.push(pre[v]);
                    lval = left.top();
                    left.pop();
                }
                else {
                    sum += d[v]+pre[v]-rval;
                    right.push(pre[v]);
                    rval = right.top();
                    right.pop();
                }
            }
            j++;
        }
        if (j == 0) continue;
        int v = elems1[i].second;
        mx1 = max(mx1, c+d[v]-pre[v]+sum);
        mx2 = max(mx2, c+d[v]+pre[v]+sum);
        // assert(mx2 < 140);
    }
    for (int i = 0; i < n; i++) {
        if (cur >= mx1+pre[i] && cur >= mx2-pre[i]) return 1;
    }
    return 0;
}

ll find_shortcut(int N, vector<int> l, vector<int> d, int c) {
    n = N;
    for (int i = 1; i < n; i++) pre[i] = pre[i-1]+l[i-1];
    for (int i = 0; i < n; i++) {
        elems1[i] = pli(pre[i]-d[i], i);
        elems2[i] = pli(pre[i]+d[i], i);
    }
    sort(elems1, elems1+n, greater<pli>());
    sort(elems2, elems2+n, greater<pli>());
    // max_dist[n-1] = d[n-1];
    // int split = n-1;
    // ll rdist = max_dist[n-1];
    // ll ldist = 0;
    // for (int i = n-2; i >= 0; i--) {
    //     ldist = max(ldist, d[i]+sum(i, split));
    //     while (split && ldist >= rdist+l[split-1]) {
    //         split--;
    //         ldist -= l[split];
    //         rdist += l[split];
    //         rdist = max(rdist, (ll)d[split]);
    //     }
    //     max_dist[i] = max(ldist, rdist);
    // }
    ll mn = 0;
    ll mx = (ll)MAXN*MAXM;
    makeable(110, d, c);
    while (mx > mn+1) {
        ll cur = (mn+mx)/2;
        if (makeable(cur, d, c)) mx = cur;
        else mn = cur;
    }
    return mx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 212 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -