답안 #778780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778780 2023-07-10T16:42:17 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];
    for (int i = 0; i < n + 5; i++){
        for (int j = 0; j < n + 5; j++)
            maks[i][j] = 0, maks2[i][j] = 0;
    }

    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; j < n; j++){
            if (dist[j] - dist[i] <= c) continue;
            ll pos = i, curr = pre[i] + suf[j] + c;
            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){
                    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]);
                pos = max(pos, (ll)k + 2);
            }

            //cout<<i<<sp<<j<<sp<<curr<<endl;
            ans = min(ans, curr);
        }
    }
    return ans;

}
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 71
6 Halted 0 ms 0 KB -