Submission #784762

# Submission time Handle Problem Language Result Execution time Memory
784762 2023-07-16T13:42:04 Z YassirSalama Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 340 KB
#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=5100;
const ll INF=1e9+10;
#define dbg(x) cout<<" [ "<<#x<<" ] : "<<x<<endl;
#define F first
#define S second
#define all(v) v.begin(),v.end()
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
    if(n==2){
        if(c<l[0])
            return d[0]+c+d[1];
        return d[0]+l[0]+d[1];
    }
    vector<long long> pref(MAXN+1,0);
    for(long long i=0;i<n-1;i++){
        pref[i+1]=pref[i]+l[i];
    }
    vector<long long> left(MAXN+1,0);
    vector<long long> right(MAXN+1,0);
    //the idea is to use pref[i-1]+l[i] or d[i]
    left[0]=(ll)d[0];
    long long first_node=0;
    for(long long i=1;i<n;i++){
        if(d[i]>left[i-1]+l[i-1]) first_node=i;
        left[i]=max(left[i-1]+l[i-1],(ll)d[i]);
    }
    long long last_node=n-1;
    right[n-1]=d[n-1];
    for(long long i=n-2;i>=0;i--){
        if(d[i]>right[i+1]+l[i]&&i!=first_node) last_node=i;
        right[i]=max(right[i+1]+l[i],(ll)d[i]);
    }
    vector<long long> nodes;//nodes in the diameter
    // cout<<first_node<<" "<<last_node<<endl;
    long long diameter=left[first_node]+right[first_node];
    // cout<<diameter<<endl;
    for(long long i=first_node;i<=last_node;i++){
        for(long long j=i+1;j<=last_node;j++){
            long long express=left[i]+c+right[j];
            long long newdiameter=0;
            for(long long k=0;k<=j;k++){
                newdiameter=max(newdiameter,(ll)abs(pref[j]-pref[k])+right[j]);
            }
            for(long long k=n-1;k>=i;k--){
                newdiameter=max(newdiameter,(ll)abs(pref[k]-pref[i])+left[i]);
            }
            // if(i==0&&j==7){
                // cout<<pref[j]-
            // }
            // cout<<newdiameter<<" "<<express<<" "<<i<<" "<<j<<endl;
            // if(newdiameter>express) continue;
            diameter=min({max(newdiameter,(ll)express),(ll)diameter}); 
        }
    }
    // cout<<c<<endl;
    return diameter;
}

// int main()
// {
//     int n, c;
//     assert(2 == scanf("%d%d", &n, &c));
    
//     std::vector<int> l(n - 1);
//     std::vector<int> d(n);
//     for (int i = 0; i < n - 1; i++)
//         assert(1 == scanf("%d", &l[i]));
//     for (int i = 0; i < n; i++)
//         assert(1 == scanf("%d", &d[i]));
        
//     long long t = find_shortcut(n, l, d, c);
    
    
//     printf("%lld\n", t);
    
//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 340 KB n = 3, 4 is a correct answer
5 Correct 0 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 340 KB n = 3, 29 is a correct answer
8 Correct 0 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 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 3000000000 vs contestant -1294967296
12 Halted 0 ms 0 KB -