답안 #1101026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101026 2024-10-15T10:28:33 Z azberjibiou Shortcut (IOI16_shortcut) C++17
0 / 100
2 ms 10748 KB
#include "shortcut.h"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=1000005;
const int mxM=2200005;
const int mxK=61;
const int MOD=1e9+7;
const ll INF=1e18;
int N;
ll A[mxN], D[mxN];
pll l[mxN];
ll r[mxN], rl[mxN], suffix_rl[mxN];
ll C;
void input(){
    cin >> N;
    for(int i=1;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> D[i];
    cin >> C;
}
void init(int n, std::vector<int> l, std::vector<int> d, int c){
    N=n;
    for(int i=1;i<N;i++) A[i]=l[i-1];
    for(int i=0;i<N;i++) D[i]=d[i];
    C=c;
}
void make_prefix(){
    for(int i=1;i<N;i++) A[i]+=A[i-1];
    // make l
    for(int i=0;i<N;i++) l[i]=pll(A[i]-D[i], i);
    sort(l, l+N);
    // make r, rl, suffix_rl
    vector <pll> v(N);
    for(int i=0;i<N;i++) v[i]=pll(A[i]+D[i], i);
    sort(all(v));
    for(int i=0;i<N;i++) r[i]=v[i].fi, rl[i]=v[i].fi-2*D[v[i].se];
    suffix_rl[N]=1e18;
    for(int i=N-1;i>=0;i--){
        suffix_rl[i]=min(suffix_rl[i+1], rl[i]);
    }
    /*
    printf("A: ");
    for(int i=0;i<N;i++) printf("%lld ", A[i]);
    printf("\nl: ");
    for(int i=0;i<N;i++) printf("(%lld %lld) ", l[i].fi, l[i].se);
    printf("\nr: ");
    for(int i=0;i<N;i++) printf("%lld ", r[i]);
    printf("\nrl: ");
    for(int i=0;i<N;i++) printf("%lld ", rl[i]);
    printf("\n");
    */
}
bool tf(ll lim){
    // c1 <= x+y <= c2, c3 <= y-x <= c4
    pll pp=pll(-1e18, 1e18), pm=pll(-1e18, 1e18);
    int rc=0;
    for(int i=0;i<N;i++){
        int now=l[i].se;
        assert(0<=now && now<N);
        if(r[N-1]-l[i].fi<=lim) break;
        while(r[rc]-l[i].fi<=lim) rc++;
        if(lim<C+D[now]) return false;
        ll delta=lim-C-D[now];
        ll lval=r[N-1]-delta, rval=suffix_rl[rc]+delta;
        pp.fi=max(pp.fi, A[now]+lval), pp.se=min(pp.se, A[now]+rval);
        pm.fi=max(pm.fi, lval-A[now]), pm.se=min(pm.se, rval-A[now]);
    }
    //printf("pp=%lld %lld, pm=%lld %lld\n", pp.fi, pp.se, pm.fi, pm.se);
    int s=0, e=0;
    for(int i=0;i<N;i++){
        while(s<N && (A[i]+A[s]<pp.fi || A[s]-A[i]<pm.fi)) s++;
        while(s-1>=0 && A[i]+A[s-1]>=pp.fi && A[s-1]-A[i]>=pm.fi) s--;
        while(e>0 && (A[i]+A[e]>pp.se || A[e]-A[i]>pm.se)) e--;
        while(e+1<N && A[i]+A[e+1]<=pp.se && A[e+1]-A[i]<=pm.se) e++;
        if(s!=N && e!=-1 && s<=e) return true;
    }
    return false;
}
ll solv(){
    make_prefix();
    ll s=0, e=1e16;
    
    while(s!=e){
        ll mid=(s+e)/2;
        if(tf(mid)) e=mid;
        else s=mid+1;
    }
    
    return e;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
    init(n, l, d, c);
    return solv();
}
/*
int main(){
    input();
    printf("%lld", solv());
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10576 KB n = 4, 80 is a correct answer
2 Correct 1 ms 10748 KB n = 9, 110 is a correct answer
3 Correct 2 ms 10576 KB n = 4, 21 is a correct answer
4 Correct 1 ms 10576 KB n = 3, 4 is a correct answer
5 Incorrect 2 ms 10712 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -