Submission #436437

# Submission time Handle Problem Language Result Execution time Memory
436437 2021-06-24T13:40:52 Z 79brue Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#include "shortcut.h"

using namespace std;

typedef long long ll;

ll minCost(vector<int> v){
    sort(v.rbegin(), v.rend());
    return v[0] + v[1];
}

int n;
ll cost;
ll arr[1000002];
ll loc[1000002];

ll vec[1000002];
ll vec2[1000002];
ll maxXpd, maxXpd2;

bool able(ll);

ll find_shortcut(int N, vector<int> l, vector<int> d, int C){
    n = N;
    for(int i=1; i<=n; i++) arr[i] = d[i-1];
    for(int i=2; i<=n; i++) loc[i] = loc[i-1] + l[i-2];
    cost = C;

    for(int i=1; i<=n; i++) vec[i] = vec2[i] = i;
    sort(vec+1, vec+n+1, [&](int a, int b){
        return arr[a] + loc[a] > arr[b] + loc[b];
    });
    sort(vec2+1, vec2+n+1, [&](int a, int b){
        return loc[a] - arr[a] > loc[b] - arr[b];
    });
    maxXpd = arr[vec[1]] + loc[vec[1]];
    maxXpd2 = arr[vec[2]] + loc[vec[2]];

    ll MIN = minCost(d), MAX = 1e18, ANS = 1e18;
    while(MIN <= MAX){
        ll MID = (MIN + MAX) / 2;
        if(able(MID)){
            ANS = MID;
            MAX = MID-1;
        }
        else MIN = MID+1;
    }
    return ANS;
}

bool able(ll X){
    ll minPlus = -1e18, maxPlus = 1e18;
    ll minMinus = -1e18, maxMinus = 1e18;

    int pnt = 1;
    ll minXmd = 1e18, minXmd2 = 1e18;
    int minXmdLoc = -1;
    for(int i=1; i<=n; i++){
        int x = vec2[i];
        while(pnt <= n && arr[vec[pnt]] + loc[vec[pnt]] > X + loc[x] - arr[x]){
            ll tmp = loc[vec[pnt]] - arr[vec[pnt]];
            if(minXmd2 > tmp){
                minXmd2 = tmp;
                if(minXmd > minXmd2) swap(minXmd, minXmd2), minXmdLoc = vec[pnt];
            }
            pnt++;
        }

        if(pnt==1 || (pnt==2 && x==vec[1]) || (pnt==2 && x==minXmdLoc)) continue;
        ll tMax = (x==vec[1] ? maxXpd2 : maxXpd);
        ll tMin = (x==minXmdLoc ? minXmd2 : minXmd);
        maxPlus = min(maxPlus, loc[x] - arr[x] + X + tMin - cost);
        minPlus = max(minPlus, loc[x] + arr[x] - X + tMax + cost);
        maxMinus = min(maxMinus, -loc[x] - arr[x] + X + tMin - cost);
        minMinus = max(minMinus, -loc[x] + arr[x] - X + tMax + cost);
    }

    int pL = n+1, pR = n;
    int mL = 1, mR = 0;
    for(int i=1; i<=n; i++){
        while(pL > 1 && loc[pL-1] + loc[i] >= minPlus) pL--;
        while(pR && loc[pR] + loc[i] > maxPlus) pR--;
        while(mL <= n && loc[i] - loc[mL] < minMinus && mL < i-1) mL++;
        while(mR <= n && loc[i] - loc[mR+1] <= maxMinus && mR < i-1) mR++;

        if(pL > pR || mL > mR) continue;
        if(pR < mL || mR < pL) continue;
        return true;
    }
    return false;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 204 KB n = 9, 110 is a correct answer
3 Correct 1 ms 204 KB n = 4, 21 is a correct answer
4 Correct 1 ms 204 KB n = 3, 4 is a correct answer
5 Correct 1 ms 204 KB n = 2, 62 is a correct answer
6 Correct 1 ms 204 KB n = 2, 3 is a correct answer
7 Correct 1 ms 204 KB n = 3, 29 is a correct answer
8 Correct 1 ms 204 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 204 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 204 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 204 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 204 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Incorrect 1 ms 332 KB n = 5, incorrect answer: jury 4000000000 vs contestant 4000000001
17 Halted 0 ms 0 KB -