Submission #1030981

# Submission time Handle Problem Language Result Execution time Memory
1030981 2024-07-22T13:12:45 Z kym Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 344 KB
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int maxn=3005;
int X[maxn];
vector<int32_t> L, D;
int C;
int n;
const int oo = 1'000'000'000'000'000'000ll;
typedef pair<int,int>pi;
int get(int L, int R){
    int dl=0,dr=0;
    for(int i=0;i<=L;i++)dl=max(dl,-X[i]+D[i]);
    for(int i=R;i<n;i++)dr=max(dr,X[i]+D[i]);
    int ans=0;
    ans=max(ans,dl+dr+min(X[R]-X[L],C)+X[L]-X[R]);

    int m1=0;
    for(int i=L+1;i<=R;i++){
        m1=max(m1,D[i] + min(X[i]-X[L], X[R]-X[i]+C));
    }
    ans=max(ans,m1 + dl+X[L]);
    int m2=0;
    for(int i=L;i<R;i++){
        m2=max(m2,D[i] + min(X[R]-X[i], X[i]-X[L]+C));
    }
    ans=max(ans,m2+dr-X[R]);
    int bet=0;
    for(int i=L;i<=R;i++){
        for(int j=i+1;j<=R;j++){
            bet=max(bet,D[i]+D[j]+min(X[j]-X[i],C+X[i]-X[L]+X[R]-X[j]));
        }
    }
    ans=max(ans,bet);
    

    vector<pi> vm1,vm2;
    for(int i=0;i<=L;i++){
        vm1.push_back({X[i]+D[i],i});
        vm2.push_back({-X[i]+D[i],i});


    }
    sort(vm1.begin(),vm1.end(),greater<pi>());
    sort(vm2.begin(),vm2.end(),greater<pi>());
    for(int i=0;i<=min(1ll,(int)vm1.size()-1);i++){
        for(int j=0;j<=min(1ll,(int)vm2.size()-1);j++){
            if(vm1[i].second != vm2[j].second){
                ans=max(ans,vm1[i].first+vm2[j].first);
            }
        }
    }

    vm1.clear();
    vm2.clear();
    for(int i=R;i<n;i++){
        vm1.push_back({X[i]+D[i],i});
        vm2.push_back({-X[i]+D[i],i});


    }
    sort(vm1.begin(),vm1.end(),greater<pi>());
    sort(vm2.begin(),vm2.end(),greater<pi>());
    for(int i=0;i<=min(1ll,(int)vm1.size()-1);i++){
        for(int j=0;j<=min(1ll,(int)vm2.size()-1);j++){
            if(vm1[i].second != vm2[j].second){
                ans=max(ans,vm1[i].first+vm2[j].first);
            }
        }
    }
    return ans;
}
long long find_shortcut(int32_t n, vector<int32_t> l, vector<int32_t> d, int32_t c)
{
    L=l;D=d;C=c;
    ::n=n;
    for(int i=1;i<n;i++){
        X[i]=X[i-1]+l[i-1];
    }  
    int ans=oo;
    for(int i=0;i<n;i++){
        vector<int> vec;
        for(int j=i+1;j<n;j++){
            int res=get(i,j);
            vec.push_back(res);
            ans=min(ans,res);
        }

        int stage=0;
        for(int k=0;k<vec.size()+1;k++){
            if(vec[k] == vec[k+1])continue;
            if(vec[k] > vec[k+1]){
                assert(stage==0);
            } else{
                stage=1;
            }
        }
    }

    return ans;
}

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int32_t, std::vector<int>, std::vector<int>, int32_t)':
shortcut.cpp:91:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(int k=0;k<vec.size()+1;k++){
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -