답안 #382927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382927 2021-03-28T14:29:08 Z doowey Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 364 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = (int)1e6 + 10;
ll pl[N];
ll pr[N];
ll cl[N];
ll ml[N];
ll mr[N];
vector<int> l;
vector<int> d;
ll lim;
int n;
ll dim;

struct segment_tree{
    ll segt[N * 2];
    int sz;
    void upd(int id, ll v){
        id += sz;
        segt[id] = v;
        id /= 2;
        while(id > 0){
            segt[id] = max(segt[id * 2], segt[id * 2 + 1]);
            id /= 2;
        }
    }
    ll get(int li, int ri){
        li += sz;
        ri += sz;
        ll val = -(ll)1e18;
        while(li <= ri){
            if(li % 2 == 1) val = max(val, segt[li ++ ]);
            if(ri % 2 == 0) val = max(val, segt[ri -- ]);
            li /= 2;
            ri /= 2;
        }
        return val;
    }
};

segment_tree rp;
segment_tree lp;

bool check(ll k){ // k < dim by binary search so a shortcut is mandatory
    int en = 0;
    ll cmp;
    for(int i = 0 ;i < n; i ++ ){
        if(i + 1 >= n)
            cmp = 0ll;
        else
            cmp = pr[i + 1] + l[i];
        cmp += d[i];
        if(cmp > k){
            rp.upd(i, cl[i] + d[i]);
        }
        else{
            rp.upd(i, -(ll)1e18);
        }
    }
    ll vv;
    for(int i = n - 1; i >= 0 ; i -- ){
        if(i == 0)
            cmp = 0ll;
        else
            cmp = pl[i - 1] + l[i - 1];
        cmp += d[i];
        if(cmp > k){
            lp.upd(i,-cl[i] + d[i]);
        }
        else{
            lp.upd(i, -(ll)1e18);
        }
    }
    bool valid;
    for(int st = 0 ; st < n ; st ++ ){
        while(en < n && (ml[st] > k || mr[en] > k || pl[st] + lim + pr[en] > k)){
            en ++ ;
        }
        while(en < n){
            // clearly st < en
            valid = true;
            vv = rp.get(st, en) + lim + pr[en] - cl[st];
            if(vv > k) valid = false;
            vv = lp.get(st, en) + cl[en] + lim + pl[st];
            if(vv > k) {
                break;
            }
            if(!valid){
                en ++ ;
            }
            else{
                return true;
            }
        }
    }
    return false;
}


ll find_shortcut(int _n, vector<int> _l, vector<int> _d, int _c){
    n = _n;
    l = _l;
    d = _d;
    lim = _c;
    for(int i = 0 ; i < n; i ++ ){
        pl[i]=d[i];
        ml[i]=d[i];
        if(i>0){
            pl[i]=max(pl[i],pl[i-1]+l[i]);
            ml[i]=max(ml[i-1],d[i]+l[i-1]+pl[i-1]);
        }
    }
    for(int i = n - 1; i >= 0; i -- ){
        pr[i]=d[i];
        mr[i]=d[i];
        if(i + 1 < n){
            pr[i]=max(pr[i],pr[i+1]+l[i]);
            mr[i]=max(mr[i+1],d[i]+l[i]+pr[i+1]);
        }
    }
    dim = ml[n-1];
    rp.sz = n;
    lp.sz = n;
    for(int i = 0 ;i + 1 < n; i ++ ){
        cl[i + 1] += cl[i] + l[i];
    }
    ll lf = 0, rf = dim;
    ll mid;
    while(lf < rf){
        mid = (lf + rf) / 2;
        if(check(mid))
            rf = mid;
        else
            lf = mid + 1;
    }
    return rf;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB n = 4, incorrect answer: jury 80 vs contestant 90
2 Halted 0 ms 0 KB -