Submission #1030968

# Submission time Handle Problem Language Result Execution time Memory
1030968 2024-07-22T13:01:23 Z kym Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 348 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 longest(vector<pi> vec){
    int tot=0;
    for(auto x:vec)tot+=x.first;
    int tar=tot/2;
    // anything <= tar, is the ans
    vector<pi> nvec=vec;
    for(auto x:vec)nvec.push_back(x);
    int cidx=0;
    int sum=0;
    int ans=0;
    multiset<int>ms;
    int curpos=0;
    int I[nvec.size()+5];
    for(int i=0;i<nvec.size();i++){
        curpos+=nvec[i].first;
        I[i]=curpos;
        

        ms.insert({-I[i]+D[nvec[i].second]});

        while(sum > tar){
            sum -= nvec[cidx].first;
            ms.erase(ms.find({-I[cidx]+D[nvec[cidx].second]}));
            ++cidx;
        }


        if(ms.size())ans=max(ans,D[nvec[i].second]+I[i]+*prev(ms.end()));
        sum += nvec[i].first;
        
    }
    return ans;
}
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;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;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);
    //ans=max(ans,longest(ls));
    //what if they just don't use it
    m1=0,m2=0;
    for(int i=0;i<=L;i++){
        m1=max(m1,X[i]+D[i]);
        m2=max(m2,-X[i]+D[i]);
    }
    ans=max(ans,m1+m2);
    m1=0,m2=0;
    for(int i=R;i<n;i++){
        m1=max(m1,X[i]+D[i]);
        m2=max(m2,-X[i]+D[i]);
    }
    ans=max(ans,m1+m2);
    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++){
        for(int j=i;j<n;j++){
            ans=min(ans,get(i,j));
        }
    }

    return ans;
}

Compilation message

shortcut.cpp: In function 'long long int longest(std::vector<std::pair<long long int, long long int> >)':
shortcut.cpp:25:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<nvec.size();i++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -