답안 #20754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20754 2017-02-16T02:01:42 Z ainta Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 105720 KB
#include "shortcut.h"
#include<stdio.h>
#include<algorithm>
#include<vector>
#define N_ 1010000
#define SZ 1048576
#define pll pair<long long, long long>
using namespace std;
int n;
long long LD[N_], RD[N_], S[N_], P[N_], IT1[SZ+SZ], IT2[SZ+SZ], TL;
long long LT[N_], RT[N_];
int RR[N_], LL[N_];
long long Max1(int b, int e){
    long long r = -1e18;
    b+=SZ;e+=SZ;
    while(b<=e){
        r=max(r,max(IT1[b],IT1[e]));
        b=(b+1)>>1,e=(e-1)>>1;
    }
    return r;
}
long long Max2(int b, int e){
    long long r = -1e18;
    b+=SZ,e+=SZ;
    while(b<=e){
        r=max(r,max(IT2[b],IT2[e]));
        b=(b+1)>>1,e=(e-1)>>1;
    }
    return r;
}
long long st[1010000][2];
bool Pos(long long d){
    if(LD[n]<=d)return true;
    int i, pv = n, ppv = 1;
    long long Mx = 0;
    for(i=1;i<=n;i++){
        if(LD[i] > d){RR[i]=-1;continue;}
        if(i!=1){
            while(1){
                long long Len = S[pv]-S[i]+TL, mm;
                if(ppv < i)ppv = i;
                if(ppv > pv)ppv = pv;
                while((S[ppv+1]-S[i])*2 <= Len && ppv+1<=pv) ppv++;
                while((S[ppv]-S[i])*2 > Len)ppv--;
                mm = Max1(i,ppv) + Mx;
                if(ppv<pv) mm = max(mm,Max2(ppv+1,pv) + Mx + S[pv]+S[i]+TL);
                if(mm > d) pv--;
                else break;
            }
        }
        RR[i] = pv;
        Mx = max(Mx, P[i]-S[i]);
    }
    Mx = 0, pv = 1, ppv = n;
    for(i=n;i>=1;i--){
        if(RD[i] > d){LL[i]=-1;continue;}
        if(i!=n){
            while(1){
                long long Len = S[i]-S[pv]+TL, mm;
                if(ppv > i)ppv = i;
                if(ppv < pv)ppv = pv;
                while((S[i]-S[ppv-1])*2 <= Len && ppv-1>=pv) ppv--;
                while((S[i]-S[ppv])*2 > Len)ppv++;
                mm = Max2(ppv,i) + Mx;
                if(ppv>pv) mm = max(mm,Max1(pv,ppv-1) + Mx - S[pv]-S[i]+TL);
                if(mm > d) pv++;
                else break;
            }
        }
        LL[i] = pv;
        Mx = max(Mx, P[i]+S[i]);
    }
    long long ML = 1e18;
    int top = 0;
    for(i=1;i<=n;i++){
        if(top && st[1][0] + P[i] + S[i] > d){
            int bb = 1, ee = top, rr=0, mid;
            while(bb<=ee){
                mid=(bb+ee)>>1;
                if(st[mid][0]+P[i]+S[i]>d){
                    rr = mid;
                    bb = mid + 1;
                }
                else ee = mid-1;
            }
            ML = min(ML, d - (st[rr][1] + P[i] - S[i]));
        }
        while(top && P[i]-S[i] >= st[top][0])top--;
        top++;
        st[top][0]=P[i]-S[i];
        st[top][1]=P[i]+S[i];
    }
    pv = 1;
    for(i=1;i<n;i++){
        pv=max(pv,i);
        while(pv+1<=n && S[pv+1]-S[i]+TL <=ML)pv++;
        if(i == pv || RR[i]==-1 || LL[pv]==-1)continue;
        if(RR[i] < pv || LL[pv] > i)continue;
        if(LT[i] + RT[pv] - (S[pv]-S[i]) + TL <= d)return true;
    }
    return false;
}
long long find_shortcut(int N, vector<int> l, vector<int> d, int c)
{
    TL = c;
    n = N;
    int i;
    for(i=1;i<=n;i++){
        if(i!=1)S[i] = S[i-1] + l[i-2];
        P[i] = d[i-1];
    }
    long long mx = 0;
    for(i=1;i<=n;i++){
        LD[i] = max(LD[i-1], mx+S[i]+P[i]);
        mx = max(mx, P[i]-S[i]);
        LT[i] = mx;
    }
    mx = S[n];
    for(i=n;i>=1;i--){
        RD[i] = max(RD[i+1], mx-S[i]+P[i]);
        mx = max(mx, P[i]+S[i]);
        RT[i] = mx;
        int t = i+SZ;
        IT1[t] = S[i]+P[i], IT2[t] = P[i]-S[i];
        while(t!=1){
            t>>=1;
            IT1[t] = max(IT1[t+t],IT1[t+t+1]);
            IT2[t] = max(IT2[t+t],IT2[t+t+1]);
        }
    }
    long long b = 0, e = LD[n], mid, res = 0;
    while(b<=e){
        mid = (b+e)/2;
        if(Pos(mid)){
            res = mid;
            e = mid - 1;
        }
        else b = mid + 1;
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 105720 KB n = 4, 80 is a correct answer
2 Correct 0 ms 105720 KB n = 9, 110 is a correct answer
3 Correct 0 ms 105720 KB n = 4, 21 is a correct answer
4 Correct 0 ms 105720 KB n = 3, 4 is a correct answer
5 Correct 0 ms 105720 KB n = 2, 62 is a correct answer
6 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
7 Correct 0 ms 105720 KB n = 3, 29 is a correct answer
8 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
9 Correct 0 ms 105720 KB n = 2, 3 is a correct answer
10 Correct 0 ms 105720 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 105720 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 105720 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 105720 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 105720 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 105720 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 105720 KB n = 10, 1000000343 is a correct answer
18 Correct 0 ms 105720 KB n = 10, 3189 is a correct answer
19 Correct 0 ms 105720 KB n = 10, 7000000000 is a correct answer
20 Correct 0 ms 105720 KB n = 5, 12 is a correct answer
21 Correct 0 ms 105720 KB n = 5, 25 is a correct answer
22 Correct 0 ms 105720 KB n = 2, 122 is a correct answer
23 Correct 0 ms 105720 KB n = 10, 117 is a correct answer
24 Incorrect 0 ms 105720 KB n = 10, incorrect answer: jury 336 vs contestant 367
25 Halted 0 ms 0 KB -