Submission #1022602

# Submission time Handle Problem Language Result Execution time Memory
1022602 2024-07-13T19:18:51 Z ttamx Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 600 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N=1e6+5;
const ll X=1e15+1e9;
const ll INF=1e18;

int n,c;
ll a[N],d[N];
vector<int> ord1,ord2;

bool check(ll k){
    ll l1=-INF,r1=INF; // x+y
    ll l2=-INF,r2=INF; // x-y
    int mx11=-1,mx12=-1,mx21=-1,mx22=-1; // d[i]+a[i],d[i]-a[i]
    auto ord=ord2;
    for(auto i:ord1){
        while(!ord.empty()&&d[i]+a[i]+d[ord.back()]-a[ord.back()]>k){
            int j=ord.back();
            ord.pop_back();
            if(mx12==-1||d[j]+a[j]>d[mx12]+a[mx12])mx12=j;
            if(mx11==-1||d[mx12]+a[mx12]>d[mx11]+a[mx11])swap(mx11,mx12);
            if(mx22==-1||d[j]-a[j]>d[mx22]-a[mx22])mx22=j;
            if(mx21==-1||d[mx22]-a[mx22]>d[mx21]-a[mx21])swap(mx21,mx22);
        }
        auto get1=[&](){
            if(mx11!=-1&&mx11!=i)return d[mx11]+a[mx11];
            return mx12!=-1?d[mx12]+a[mx12]:-INF;
        };
        auto get2=[&](){
            if(mx21!=-1&&mx21!=i)return d[mx21]-a[mx21];
            return mx22!=-1?d[mx22]-a[mx22]:-INF;
        };
        l1=max(l1,d[i]+a[i]+get1()-k+c);
        r1=min(r1,-(d[i]-a[i])-get2()+k-c);
        l2=max(l2,d[i]+a[i]+get2()-k+c);
        r2=min(r2,-(d[i]-a[i])-get1()+k-c);
    }
    if(l1>r1||l2>r2)return false;
    int pl1=n-1,pr1=n,pl2=-1,pr2=0;
    for(int i=0;i<n;i++){
        ll y=a[i];
        while(pl1>=0&&a[pl1]+y>=l1)pl1--;
        while(pl2+1<n&&a[pl2+1]-y<l2)pl2++;
        while(pr2>0&&a[pr2-1]+y>r1)pr2--;
        while(pr2<n&&a[pr2]-y<=r2)pr2++;
        if(min(pr1,pr2)-max({pl1,pl2,i})>1)return true;
    }
    return false;
}

ll find_shortcut(int _n,vector<int> _l,vector<int> _d,int _c){
    n=_n,c=_c;
    for(int i=0;i+1<n;i++)a[i+1]=a[i]+_l[i];
    for(int i=0;i<n;i++)d[i]=_d[i];
    ord1.resize(n);
    iota(ord1.begin(),ord1.end(),0);
    ord2=ord1;
    sort(ord1.begin(),ord1.end(),[&](int i,int j){return d[i]+a[i]<d[j]+a[j];});
    sort(ord2.begin(),ord2.end(),[&](int i,int j){return d[i]-a[i]<d[j]-a[j];});
    ll l=0LL,r=X;
    while(l<r){
        ll m=(l+r)/2;
        if(check(m))r=m;
        else l=m+1;
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 4, 80 is a correct answer
2 Correct 0 ms 348 KB n = 9, 110 is a correct answer
3 Correct 0 ms 348 KB n = 4, 21 is a correct answer
4 Correct 0 ms 348 KB n = 3, 4 is a correct answer
5 Correct 1 ms 348 KB n = 2, 62 is a correct answer
6 Correct 0 ms 348 KB n = 2, 3 is a correct answer
7 Correct 0 ms 348 KB n = 3, 29 is a correct answer
8 Correct 0 ms 348 KB n = 2, 3 is a correct answer
9 Correct 0 ms 440 KB n = 2, 3 is a correct answer
10 Correct 1 ms 348 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 348 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 348 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 348 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 348 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 348 KB n = 5, 4000000000 is a correct answer
17 Correct 0 ms 348 KB n = 10, 1000000343 is a correct answer
18 Incorrect 1 ms 344 KB n = 10, incorrect answer: jury 3189 vs contestant 3115
19 Halted 0 ms 0 KB -