Submission #617965

# Submission time Handle Problem Language Result Execution time Memory
617965 2022-08-01T18:12:57 Z Bench0310 Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 300 KB
#include <bits/stdc++.h>
#include "shortcut.h"

using namespace std;
typedef long long ll;

struct ST
{
    int n;
    vector<ll> val;
    vector<array<ll,2>> tree;
    ST(vector<ll> &d)
    {
        n=d.size();
        val=d;
        tree.resize(4*n);
        build(1,0,n-1);
    }
    void build(int idx,int l,int r)
    {
        if(l==r) tree[idx]={val[l],l};
        else
        {
            int m=(l+r)/2;
            build(2*idx,l,m);
            build(2*idx+1,m+1,r);
            tree[idx]=max(tree[2*idx],tree[2*idx+1]);
        }
    }
    void update(int idx,int l,int r,int pos,ll x)
    {
        if(l==r) tree[idx][0]=x;
        else
        {
            int m=(l+r)/2;
            if(pos<=m) update(2*idx,l,m,pos,x);
            else update(2*idx+1,m+1,r,pos,x);
            tree[idx]=max(tree[2*idx],tree[2*idx+1]);
        }
    }
    void upd(int pos,ll x){update(1,0,n-1,pos,x);}
    array<ll,2> query(int idx,int l,int r,int ql,int qr)
    {
        if(ql>qr) return {-(1ll<<60),-1};
        if(l==ql&&r==qr) return tree[idx];
        int m=(l+r)/2;
        return max(query(2*idx,l,m,ql,min(qr,m)),query(2*idx+1,m+1,r,max(ql,m+1),qr));
    }
    array<ll,2> qry(int ql,int qr){return query(1,0,n-1,ql,qr);}
};

ll find_shortcut(int n,vector<int> len,vector<int> d,int c)
{
    vector<ll> lsum(n,0);
    for(int i=1;i<n;i++) lsum[i]=lsum[i-1]+len[i-1];
    vector<ll> rsum(n,0);
    for(int i=n-2;i>=0;i--) rsum[i]=rsum[i+1]+len[i];
    auto sum=[&](int l,int r)->ll{return (lsum[r]-lsum[l]);};
    vector<ll> dl(n,0);
    vector<ll> mxl(n,0);
    for(int i=0;i<n;i++)
    {
        ll nxt=(i>0?dl[i-1]+len[i-1]:ll(0));
        dl[i]=max(nxt,ll(d[i]));
        mxl[i]=max((i>0?mxl[i-1]:ll(0)),nxt+d[i]);
    }
    vector<ll> dr(n,0);
    vector<ll> mxr(n,0);
    for(int i=n-1;i>=0;i--)
    {
        ll nxt=(i<n-1?dr[i+1]+len[i]:ll(0));
        dr[i]=max(nxt,ll(d[i]));
        mxr[i]=max((i<n-1?mxr[i+1]:ll(0)),nxt+d[i]);
    }
    vector<ll> tmpl(n,0);
    for(int i=0;i<n;i++) tmpl[i]=rsum[i]+d[i];
    vector<ll> tmpr(n,0);
    for(int i=0;i<n;i++) tmpr[i]=lsum[i]+d[i];
    ST gol(tmpl);
    ST gor(tmpr);
    auto C=[&](int l,int r)->ll
    {
        ll diam=max(mxl[l],mxr[r]);
        ll cycle=sum(l,r)+c;
        gol.upd(l,rsum[l]+dl[l]);
        gor.upd(l,lsum[l]+dl[l]);
        gol.upd(r,rsum[r]+dr[r]);
        gor.upd(r,lsum[r]+dr[r]);
        auto getd=[&](int i)->ll
        {
            if(i==l) return dl[i];
            if(i==r) return dr[i];
            return d[i];
        };
        auto opt=[&](int p)->array<ll,2>
        {
            array<ll,2> tmp={-1,-1};
            //left
            int tl=l-1,tr=p;
            while(tl<tr-1)
            {
                int m=(tl+tr)/2;
                if(sum(m,p)<=cycle/2) tr=m;
                else tl=m;
            }
            auto [d1,i1]=gol.qry(tr,p-1);
            tmp=max(tmp,{d1-rsum[p]+getd(p),i1});
            auto [d2,i2]=gor.qry(l,tl);
            tmp=max(tmp,{d2-lsum[l]+sum(p,r)+c+getd(p),i2});
            //right
            tl=p,tr=r+1;
            while(tl<tr-1)
            {
                int m=(tl+tr)/2;
                if(sum(p,m)<=cycle/2) tl=m;
                else tr=m;
            }
            auto [d3,i3]=gor.qry(p+1,tl);
            tmp=max(tmp,{d3-lsum[p]+getd(p),i3});
            auto [d4,i4]=gol.qry(tr,r);
            tmp=max(tmp,{d4-rsum[r]+sum(l,p)+c+getd(p),i4});
            return tmp;
        };
        diam=max(diam,opt(opt(l)[1])[0]);
        gol.upd(l,rsum[l]+d[l]);
        gor.upd(l,lsum[l]+d[l]);
        gol.upd(r,rsum[r]+d[r]);
        gor.upd(r,lsum[r]+d[r]);
        return diam;
    };
    ll res=(1ll<<60);
    for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) res=min(res,C(i,j));
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 300 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 212 KB n = 5, 4000000000 is a correct answer
17 Correct 1 ms 300 KB n = 10, 1000000343 is a correct answer
18 Correct 1 ms 232 KB n = 10, 3189 is a correct answer
19 Incorrect 1 ms 212 KB n = 10, incorrect answer: jury 7000000000 vs contestant 6000000000
20 Halted 0 ms 0 KB -