Submission #921087

# Submission time Handle Problem Language Result Execution time Memory
921087 2024-02-03T09:56:14 Z danikoynov Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 348 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 3010;
const ll inf = 1e18;
int n;
ll cp[maxn], cs[maxn], pref[maxn], bef[maxn], aft[maxn];
ll l[maxn], d[maxn], c;

ll dist[maxn];
struct edge
{
    int to;
    ll w;

    edge(int _to = 0, ll _w = 0)
    {
        to = _to;
        w = _w;
    }

    bool operator < (const edge &e) const
    {
        return w > e.w;
    }
};

int used[maxn];

ll get_dist(int l, int r)
{
    if (l > r)
        swap(l, r);
    return pref[r - 1] - pref[l - 1];
}

ll find_shortcut(int N, vector<int> L, 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];

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

    for (int i = 1; i <= n; i ++)
    {
        cp[i] = cp[i - 1] + l[i - 1];
        cp[i] = max(cp[i], d[i]);
        bef[i] = bef[i - 1];
        for (int j = 1; j < i; j ++)
        {
            bef[i] = max(bef[i], get_dist(i, j) + d[i] + d[j]);
        }
    }

    for (int i = n; i > 0; i --)
    {
        cs[i] = cs[i + 1] + l[i];
        cs[i] = max(cs[i], d[i]);
        aft[i] = aft[i + 1];
        for (int j = i + 1; j <= n; j ++)
        {
            aft[i] = max(aft[i], get_dist(i, j) + d[i] + d[j]);
        }
    }

    ll ans = inf;
    for (int l = 1; l <= n; l ++)
    {
        for (int r = l + 1; r <= n; r ++)
        {
            ll res = max(bef[l], aft[r]), len = pref[r - 1] - pref[l - 1] + c;

            multiset < ll > act, rev;
            int  rb = l - 1;
            for (int i = l; i <= r; i ++)
            {
                if (i != r)
                rev.insert({-pref[i - 1] + d[i]});
                else
                rev.insert({-pref[i - 1] + cs[i]});
            }
            for (int i = l; i <= r; i ++)
            {
                /**int lf = i, rf = r;
                while(lf <= rf)
                {
                    int mf = (lf + rf) / 2;
                    if (get_dist(i, mf) <= len - get_dist(i, mf))
                        lf = mf + 1;
                    else
                        rf = mf - 1;
                }*/

                while(rb < r)
                {
                    if (get_dist(i, rb + 1) <= len - get_dist(i, rb + 1))
                    {
                        rb ++;
                        if (rb != r)
                        {
                            rev.erase(rev.find(-pref[rb - 1] + d[rb]));
                            act.insert({pref[rb - 1] + d[rb]});
                        }
                        else
                        {
                            rev.erase(rev.find(-pref[rb - 1] + cs[rb]));
                            act.insert({pref[rb - 1] + cs[rb]});
                        }
                    }
                    else
                        break;
                }


                if (i != r)
                    act.erase(act.find(pref[i - 1] + d[i]));
                else
                    act.erase(act.find(pref[i - 1] + cs[i]));

                if (!act.empty())
                {
                    ll path = *act.rbegin() - pref[i - 1] + d[i];
                    if (i == l)
                        path = path - d[i] + cp[i];
                    res = max(res, path);
                }

                /**for (int j = i + 1; j <= rb; j ++)
                {
                    ll path = get_dist(i, j) + d[i] + d[j];
                    if (i == l)
                        path = path - d[i] + cp[i];
                    if (j == r)
                        path = path - d[j] + cs[j];
                    res = max(res, path);
                }*/

                if (!rev.empty())
                {
                    ll path = *rev.rbegin() + pref[i - 1] + d[i] + c;
                    if (i == l)
                        path = path - d[i] + cp[i];
                    res = max(res ,path);
                }
                /**
                for (int j = rb + 1; j <= r; j ++)
                {
                    ll path = len - get_dist(i, j) + d[i] + d[j];
                    if (i == l)
                        path = path - d[i] + cp[i];
                    if (j == r)
                        path = path - d[j] + cs[j];
                    res = max(res, path);
                }*/
                /**for (int j = i + 1; j <= r; j ++)
                {
                    ll path = min(len - get_dist(i, j), get_dist(i, j)) + d[i] + d[j];
                    if (i == l)
                        path = path - d[i] + cp[i];
                    if (j == r)
                        path = path - d[j] + cs[j];
                    res = max(res, path);
                }*/
            }
            ///cout << "range " << l << " " << r << " "
            ans = min(ans, res);


        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -