Submission #71608

# Submission time Handle Problem Language Result Execution time Memory
71608 2018-08-25T08:31:34 Z top34051 Shortcut (IOI16_shortcut) C++17
0 / 100
5 ms 460 KB
#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int maxn = 3e5 + 5;
const ll inf = 1e16;

int n;
ll cost, len[maxn], val[maxn];
ll pos[maxn];
int a[maxn], b[maxn];

bool check(ll k) {
//    printf("check %lld\n",k);
    ll r1 = -inf, r2 = inf, c1 = -inf, c2 = inf;
    ll mx = -inf;
    for(int i=0,j=-1;i<n;i++) {
        int x = a[i];
        while(j+1<n && val[a[i]]-pos[a[i]] > k-(val[b[j+1]]+pos[b[j+1]])) {
            j++;
            int y = b[j];
            mx = max(mx,pos[y]+val[y]);
        }
        r1 = max(r1, pos[x] + val[x] - k + cost + mx);
        c1 = max(c1, -pos[x] + val[x] - k + cost + mx);
    }
    ll mn = inf;
    for(int i=0,j=-1;i<n;i++) {
        int x = a[i];
        while(j+1<n && val[a[i]]-pos[a[i]] > k-(val[b[j+1]]+pos[b[j+1]])) {
            j++;
            int y = b[j];
            mn = min(mn,pos[y]-val[y]);
        }
        r2 = min(r2, pos[x] - val[x] + k - cost + mn);
        c2 = min(c2, -pos[x] - val[x] + k - cost + mn);
    }
    if(r1 > r2 || c1 > c2) return 0;
    for(int i=0;i<n;i++) {
        ll L = max(r1-pos[i],c1+pos[i]), R = min(r2-pos[i],c2+pos[i]);
        int j = lower_bound(&pos[0],&pos[n],L) - &pos[0];
        if(j<n && pos[j]<=R) return 1;
    }
    return 0;
}

ll solve() {
    for(int i=0;i<n-1;i++) pos[i+1] = pos[i] + len[i];
    for(int i=0;i<n;i++) a[i] = b[i] = i;
    sort(&a[0],&a[n],[&](int x, int y){return val[x]-pos[x] < val[y]-pos[y];});
    sort(&b[0],&b[n],[&](int x, int y){return val[x]+pos[x] > val[y]+pos[y];});
    ll l = 0, r = inf, mid, res = -1;
    while(l<=r) {
        mid = (l+r)/2;
        if(check(mid)) {
            res = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    return res;
}

ll find_shortcut(int N, vector<int> l, vector<int> d, int c) {
    n = N; cost = c;
    for(int i=0;i<n-1;i++) len[i] = l[i];
    for(int i=0;i<n;i++) val[i] = d[i];
    return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 3 ms 460 KB n = 4, 21 is a correct answer
4 Correct 2 ms 460 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 460 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -