답안 #756544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756544 2023-06-11T21:12:41 Z alexander707070 Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
#define MAXN 1007
using namespace std;

const long long inf=1e15;

int n;
long long pref[MAXN],suff[MAXN],sum[MAXN],dist[MAXN];
long long curr,ans,c,d1,d2,e;

multiset<long long> s;
multiset<long long>::iterator it;

long long getmax(){
    it=s.end(); it--;
    return *it;
}

void dfs(int x,int p,int l,int r,long long lim,long long s){
    e=max(e,s+dist[x]);
    if(x==l and p!=r and s+c<=lim)dfs(r,l,l,r,lim,s+c);
    if(x==r and p!=l and s+c<=lim)dfs(l,r,l,r,lim,s+c);
    if(x<r and x+1!=p and s+sum[x+1]-sum[x]<=lim)dfs(x+1,x,l,r,lim,s+sum[x+1]-sum[x]);
    if(x>l and x-1!=p and s+sum[x]-sum[x-1]<=lim)dfs(x-1,x,l,r,lim,s+sum[x]-sum[x-1]);
}

long long cycle(int from,int to){
    long long ss=sum[to]-sum[from]+c,res=0,len=0,torem=0;
    int pt=from;

    s.clear();
    s.insert(dist[from]);

    for(int i=from;i<=to;i++){
        while(true){
            if(pt>=i and pt<to and sum[pt+1]-sum[i]<=ss/2){len=sum[pt+1]-sum[i]; pt++; s.insert(len+dist[pt]+torem);}
            else if(pt==to and sum[to]-sum[i]+c<=ss/2){len=sum[to]-sum[i]+c; pt=from; s.insert(len+dist[pt]+torem);}
            else if(pt<i and sum[to]-sum[i]+c+sum[pt+1]-sum[from]<=ss/2){len=sum[to]-sum[i]+c+sum[pt+1]-sum[from]; pt++; s.insert(len+dist[pt]+torem);}
            else break;
        }

        res=max(res,getmax()-torem);
        torem+=sum[i+1]-sum[i];
    }

    e=0; dfs(from,0,from,to,ss/2,0); d1=e;
    e=0; dfs(to,0,from,to,ss/2,0); d2=e;

    return res;
}

long long find_shortcut(int N,vector<int> l,vector<int> d, int C){
    n=N; c=C;

    for(int i=1;i<=n;i++){
        dist[i]=d[i-1];
    }

    pref[1]=d[0]; sum[1]=0;
    for(int i=0;i<l.size();i++){
        pref[i+2]=max(pref[i+1]+l[i],d[i+1]*1LL);
        sum[i+2]=sum[i+1]+l[i];
    }

    suff[n]=d[n-1];
    for(int i=l.size()-1;i>=0;i--){
        suff[i+1]=max(suff[i+2]+l[i],d[i]*1LL);
    }

    ans=inf;
    for(int i=1;i<=n;i++){
        for(int f=i+1;f<=n;f++){
            if(sum[f]-sum[i]<=c)continue;

            curr=pref[i]+c+suff[f];
            curr=max(curr,cycle(i,f));
            curr=max(curr,max(d1+pref[i],d2+suff[f]));

            cout<<i<<" "<<f<<" "<<d1<<" "<<d2<<" "<<curr<<"\n";
            ans=min(ans,curr);
        }
    }

    return ans;
}

/*
int main(){
    cout<<find_shortcut(4, {10, 20, 20}, {0, 40, 0, 30}, 10)<<"\n";

    //cout<<find_shortcut(9, {10, 10, 10, 10, 10, 10, 10, 10}, {20, 0, 30, 0, 0, 40, 0, 40, 0}, 30)<<"\n";
}
*/

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i=0;i<l.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Secret is incorrect!
2 Halted 0 ms 0 KB -