Submission #1026341

# Submission time Handle Problem Language Result Execution time Memory
1026341 2024-07-18T00:30:06 Z vjudge1 Shortcut (IOI16_shortcut) C++17
Compilation error
0 ms 0 KB
#include "shortcut.h"
using namespace std;
long long ans=1e18,lofn;
vector<long long>prf,dep,len;
long long precalc[3010][3010];
bool checklr(int lend,int rend){
    vector<long long>dep2=dep,origd;
    long long vl=0,mxpos=0;
    for(int i=2;i<=lend;i++){
        vl=max(vl,dep2[i]+len[i-1]+dep2[i-1]);
        dep2[i]=max(dep2[i],dep2[i-1]+len[i-1]);
    }
    for(int i=dep.size();--i>rend;){
        long long gameover=dep2[i]+len[i-1]+dep2[i-1];
        if(vl<gameover)vl=gameover,mxpos=rend;
        dep2[i-1]=max(dep2[i-1],dep2[i]+len[i-1]);
    }
    origd=dep2;
    for(int i=lend+1;i<=rend;i++)
        dep2[i]=max(dep2[i-1],prf[i]-prf[lend]+dep2[i]);
    dep2[lend-1]=-1e18;
    long long KY=prf[rend]-prf[lend]+lofn;
    int pt=rend;
    for(int i=rend;i>lend;i--){
        while(pt>lend&&prf[i]-prf[pt-1]<=KY/2)
            pt--;
        long long tis=dep2[pt-1]+lofn+origd[rend]-prf[i]+prf[rend];
        long long tis2=origd[i]+prf[i]+max(pt==lend?origd[lend]-prf[lend]:dep2[lend-1],precalc[pt][i-1]);
        long long tis3=max(tis,tis2);
        if(tis3>vl) mxpos=i,vl=tis3;
    }
    ans=min(ans,vl);
    return mxpos==rend;
}
long long checkvl(int lend,int rend){
    vector<long long>dep2=dep,len=len,origd;
    long long vl=0;
    for(int i=2;i<=lend;i++){
        vl=max(vl,dep2[i]+len[i-1]+dep2[i-1]);
        dep2[i]=max(dep2[i],dep2[i-1]+len[i-1]);
    }
    for(int i=dep.size();--i>rend;){
        vl=max(vl,dep2[i]+len[i-1]+dep2[i-1]);
        dep2[i-1]=max(dep2[i-1],dep2[i]+len[i-1]);
    }
    origd=dep2;
    for(int i=lend+1;i<=rend;i++)
        dep2[i]=max(dep2[i-1],prf[i]-prf[lend]+dep2[i]);
    dep2[lend-1]=-1e18;
    long long KY=prf[rend]-prf[lend]+lofn;
    int pt=rend;
    for(int i=rend;i>lend;i--){
        while(pt>lend&&prf[i]-prf[pt-1]<=KY/2)
            pt--;
        long long tis=dep2[pt-1]+lofn+origd[rend]-prf[i]+prf[rend];
        long long tis2=origd[i]+prf[i]+max(pt==lend?origd[lend]-prf[lend]:dep2[lend-1],precalc[pt][i-1]);
        vl=max(vl,max(tis,tis2));
    }
    ans=min(ans,vl);
    return vl;
}
void DNC(int l,int r,int opl,int opr){
    if(l>r)return;
    int mid=l+r>>1,opt=0;
    long long VD=1e18;
    for(int i=max(mid+1,opl);i<=opr;i++) {
        long long k=checkvl(mid,i);
        if(VD>k) VD=k,opt=i;
    }
    DNC(l,mid-1,opl,opt);
    DNC(mid+1,r,opt,opr);
}
void binsearch(int l){
    int L=l+1,R=dep.size()-1;
    for(int i=L;i<=R;i++)
        checklr(l,i);
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
    lofn=c;
    dep=len={0};
    prf={0,0};
    for(auto i:l)
        len.push_back(i),
        prf.push_back(i);
    for(auto i:d)
        dep.push_back(i);
    memset(precalc,-7,sizeof precalc);
    for(int i=1;i<=n;i++)
        prf[i]+=prf[i-1],precalc[i][i]=dep[i]-prf[i];
    for(int i=n-1;i;i--) for(int j=i+1;j<=n;j++)
        precalc[i][j]=max(precalc[i][j-1],dep[j]-prf[j]);
    //DNC(1,n-1,1,n);
    for(int i=1;i<n;i++)
        binsearch(i);
    return ans;
}

Compilation message

shortcut.cpp: In function 'void DNC(int, int, int, int)':
shortcut.cpp:64:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     int mid=l+r>>1,opt=0;
      |             ~^~
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:87:5: error: 'memset' was not declared in this scope
   87 |     memset(precalc,-7,sizeof precalc);
      |     ^~~~~~
shortcut.cpp:2:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    1 | #include "shortcut.h"
  +++ |+#include <cstring>
    2 | using namespace std;