답안 #71627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71627 2018-08-25T09:13:58 Z top34051 Shortcut (IOI16_shortcut) C++17
0 / 100
3 ms 492 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];

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