Submission #778446

# Submission time Handle Problem Language Result Execution time Memory
778446 2023-07-10T10:29:29 Z vjudge1 Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#include "shortcut.h"
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define ll long long

const ll INF = 2e18 + 7;

long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
    vector<ll> pre(n + 5, 0), suf(n + 5, 0), dist(n + 5, 0);
    ll maks[n + 5][n + 5], maks2[n + 5][n + 5];
    pre[0] = d[0];
    for (int i = 1; i < n; i++){
        pre[i] = pre[i - 1] + l[i - 1];
        pre[i] = max(pre[i], (ll)d[i]);
    }

    suf[n - 1] = d[n - 1];
    for (int i = n - 2; i >= 0; i--){
        suf[i] = suf[i + 1] + l[i];
        suf[i] = max(suf[i], (ll)d[i]);
    }
    for (int i = 1; i < n; i++)
        dist[i] = dist[i - 1] + l[i - 1];

    for (int i = 0; i < n; i++){
        maks[i][i] = d[i];
        for (int j =  i -1; j >= 0; j--){
            maks[j][i] = max(maks[j + 1][i], dist[i] - dist[j] + d[j]);
        }
    }

    for (int i = 0; i < n; i++){
        maks2[i][i] = d[i];
        for (int j = i + 1; j < n; j++){
            maks2[i][j] = max(maks2[i][j - 1], dist[j] - dist[i] + d[j] + d[i]);
        }
    }


    ll ans = 0;
    for (int i = 0; i < n; i++){
        ans = max(ans, (ll)d[i]);
        for (int j = i + 1; j < n; j++){
            ans = max(ans, dist[j] - dist[i] + d[i] + d[j]);
        }
    }

    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            if (dist[j] - dist[i] <= c) continue;
            ll pos = i, curr = pre[i] + suf[j] + c;
            ll makss = -INF;
            for (int k = i; k <= j; k++){
                curr = max(curr, suf[j] + d[k] + min(dist[k] - dist[i] + c, dist[j] - dist[k]));
                curr = max(curr, pre[i] + d[k] + min(dist[k] - dist[i], dist[j] - dist[k] + c));

                while(pos <= j && dist[pos] - dist[k] < dist[j] - dist[pos] + dist[k] - dist[i] + c){
                    makss = max(makss, d[pos] + dist[pos]);
                    pos++;
                }
                if (pos <= j) curr = max(curr, d[k] + dist[k] - dist[i] + c + maks[pos][j]);
                if (pos > k) curr = max(curr, maks2[k][pos - 1]);
                curr = max(curr, (ll)d[k]);
            }
            //cout<<i<<sp<<j<<sp<<curr<<endl;
            ans = min(ans, curr);
        }
    }
    return ans;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 1 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -