Submission #745100

# Submission time Handle Problem Language Result Execution time Memory
745100 2023-05-19T11:59:13 Z boris_mihov Shortcut (IOI16_shortcut) C++17
0 / 100
0 ms 212 KB
#include "shortcut.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 100000 + 10;
const llong INF = 1e18;

int n, c;
int l[MAXN];
int d[MAXN];
llong p[MAXN];

llong abs(const llong &num)
{
    if (num < 0) return -num;
    return num;
}

llong check(int from, int to)
{
    llong res = 0;
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = i + 1 ; j <= n ; ++j)
        {
            res = std::max(res, std::min(p[j] - p[i], abs(p[i] - p[from]) + abs(p[j] - p[to]) + c) + d[i] + d[j]);
        }
    }

    return res;
}

llong ans = INF;
void divide(int l, int r, int optL, int optR)
{
    int opt = -1;
    llong currAns = INF;
    int mid = (l + r) / 2;
    for (int i = std::max(mid + 1, optL) ; i <= optR ; ++i)
    {
        llong curr = check(mid, i);
        if (curr < currAns)
        {
            currAns = curr;
            opt = i;
        }
    }

    ans = std::min(ans, currAns);
    if (opt == -1)
    {
        opt = mid;
    }

    if (l < mid) divide(l, mid - 1, optL, opt);
    if (mid < r) divide(mid + 1, r, opt, optR);
}

llong find_shortcut(int N, std::vector <int> L, std::vector <int> D, int C)
{
    n = N; c = C;
    for (int i = 0 ; i < n - 1 ; ++i)
    {
        l[i + 1] = L[i]; 
    }

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

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

    divide(1, n, 1, n);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Incorrect 0 ms 212 KB n = 9, incorrect answer: jury 110 vs contestant 120
3 Halted 0 ms 0 KB -