답안 #20768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20768 2017-02-16T03:48:11 Z ainta Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 424084 KB
#include "shortcut.h"
#include<stdio.h>
#include<algorithm>
#include<cstdlib>
#include<vector>
#define N_ 1010000
#define SZ 1048576
#define pll pair<long long, long long>
using namespace std;
int n, lower[N_];
long long LD[N_], RD[N_], S[N_], P[N_], IT1[N_][20], IT2[N_][20], TL;
long long LT[N_], RT[N_];
int RR[N_], LL[N_];
long long Max1(int b, int e){
    int t = lower[e-b+1];
    return max(IT1[b][t], IT1[e-(1<<t)+1][t]);
}
long long Max2(int b, int e){
    int t = lower[e-b+1];
    return max(IT2[b][t], IT2[e-(1<<t)+1][t]);
}
long long st[1010000][2];
struct point{
    long long a, b;
    bool operator<(const point &p)const{
        return a<p.a;
    }
}AA[N_], BB[N_];
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(pv>i && pv!=-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;
            }
        }
        if(pv<=i)pv=-1;
        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(pv<i && pv!=-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;
            }
        }
        if(pv>=i)pv=-1;
        LL[i] = pv;
        Mx = max(Mx, P[i]+S[i]);
    }
    long long ML = 1e18;
    Mx = -1e18;
    pv = n+1;
    for(i=1;i<=n;i++){
        while(pv>1 && BB[pv-1].a + AA[i].a > d){
            pv--;
            Mx = max(Mx, BB[pv].b);
        }
        ML = min(ML, d - (Mx + AA[i].b));
    }
    for(i=1;i<n;i++){
        pv=max(pv,i);
        while(pv+1<=n && S[pv+1]-S[i]+TL <=ML)pv++;
        int t = min(pv, RR[i]);
        if(t <= i || LL[t]==-1)continue;
        if(LL[t] > i)continue;
        if(LT[i] + RT[t] - (S[t]-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, j;
    for(i=1;i<=n;i++){
        lower[i]=lower[i-1];
        if((1<<(lower[i]+1)) <= i)lower[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;
        IT1[i][0] = S[i]+P[i], IT2[i][0] = P[i]-S[i];
    }
    for(i=1;i<=n;i++){
        AA[i].a = S[i]+P[i], AA[i].b = P[i]-S[i];
        BB[i].a = P[i]-S[i], BB[i].b = S[i]+P[i];
    }
    sort(AA+1,AA+n+1);
    sort(BB+1,BB+n+1);
    for(i=0;i<19;i++){
        for(j=1;j<=n;j++){
            if(j+(1<<(i+1)) - 1 > n)continue;
            IT1[j][i+1] = max(IT1[j][i],IT1[j+(1<<i)][i]);
            IT2[j][i+1] = max(IT2[j][i],IT2[j+(1<<i)][i]);
        }
    }
    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 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 424084 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 424084 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -