Submission #1062872

#TimeUsernameProblemLanguageResultExecution timeMemory
1062872nvujicaShortcut (IOI16_shortcut)C++14
0 / 100
20 ms600 KiB
#include <bits/stdc++.h>
#include "shortcut.h"
#define ll long long

using namespace std;

const int maxn = 505;
const ll inf = (1LL << 60);

int n, c;
vector <int> l;
vector <int> d;
ll dpoc[maxn];

ll f(int a, int b){
    ll maks = 0;

    for(int x = 0; x < n; x++){
        for(int y = x + 1; y < n; y++){
            ll dxa = abs(dpoc[x] - dpoc[a]);
            ll dxb = abs(dpoc[x] - dpoc[b]);
            ll dya = abs(dpoc[y] - dpoc[a]);
            ll dyb = abs(dpoc[y] - dpoc[b]);
            ll dxy = abs(dpoc[x] - dpoc[y]);
            dxa = min(dxa, dxb + c);
            dxb = min(dxb, dxa + c);
            dya = min(dya, dyb + c);
            dyb = min(dyb, dya + c);

            // maks = max(maks, dxy + d[x] + d[y]);
            maks = max(maks, min(dxy, min(dxa + dya, dxb + dyb)) + d[x] + d[y]);
            // if(maks == 110) cout << x << ' ' << y << ' ' << dxa << ' ' << dya << endl;
        }
    }

    return maks;
}

ll find_shortcut(int _n, vector<int> _l, vector<int> _d, int _c){
    n = _n;
    l = _l;
    d = _d;
    c = _c;

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

    ll ans = inf;

    for(int a = 0; a < n; a++){
        int lo = 0, hi = n - 1;

        while(lo < hi){
            int mid = (lo + hi) / 2;
            
            ll maks1 = f(a, mid);
            ll maks2 = f(a, mid + 1);
            ans = min(ans, maks1);
            ans = min(ans, maks2);

            if(maks1 <= maks2) hi = mid;
            else lo = mid + 1;

            // cout << a << ' ' << b << ' ' << maks << endl;

            // ans = min(ans, maks);
        }

        ans = min(ans, f(a, hi));
    }
    
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...