답안 #71618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71618 2018-08-25T08:44:31 Z top34051 Shortcut (IOI16_shortcut) C++17
0 / 100
3 ms 620 KB
#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;

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

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

void update(int t, int x, ll val) {
    while(x>0) {
        if(t==0) tree[x] = max(tree[x], val);
        else tree[x] = min(tree[x], val);
        x -= x&-x;
    }
}

ll query(int t, int x) {
    ll res = (t==0 ? -inf : inf);
    while(x<n) {
        if(t==0) res = max(res, tree[x]);
        else res = min(res, tree[x]);
        x += x&-x;
    }
    return res;
}

bool check(ll k) {
//    printf("check %lld\n",k);
    ll r1 = -inf, r2 = inf, c1 = -inf, c2 = inf;
    for(int i=0;i<n;i++) tree[i] = -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];
            //update(0,y,pos[y]+val[y]);
            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);
    }
    for(int i=0;i<n;i++) tree[i] = inf;
    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];
            //update(1,y,pos[y]-val[y]);
            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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 536 KB n = 4, 21 is a correct answer
4 Correct 2 ms 620 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 620 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -