답안 #591764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591764 2022-07-07T20:51:57 Z AlperenT Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include "shortcut.h"

using namespace std;

const long long INF = 1e9 + 5;

vector<long long> prefix, leftmax, rightmax, leftansmax, rightansmax;

long long getdist(int x, int y){
    return prefix[y - 1] - prefix[x - 1];
}

long long find_shortcut(int n, vector<int> ln, vector<int> d, int c){
    ln.insert(ln.begin(), 0), d.insert(d.begin(), 0);
    long long ans = INF;

    prefix.assign(n + 2, 0);
    leftmax.assign(n + 2, 0), rightmax.assign(n + 2, 0);
    leftansmax.assign(n + 2, 0), rightansmax.assign(n + 2, 0);

    for(int i = 1; i < n; i++) prefix[i] = prefix[i - 1] + ln[i];

    for(int i = 1; i <= n; i++){
        leftmax[i] = max(leftmax[i - 1] + ln[i - 1], (long long)d[i]); 
        leftansmax[i] = max(leftansmax[i - 1], leftmax[i - 1] + ln[i - 1] + d[i]);
    }
    for(int i = n; i >= 1; i--){
        rightmax[i] = max(rightmax[i + 1] + ln[i], (long long)d[i]); 
        rightansmax[i] = max(rightansmax[i + 1], rightmax[i + 1] + ln[i] + d[i]);
    }

    for(int l = 1; l <= n; l++){
        for(int r = l + 1; r <= n; r++){
            long long curans = leftmax[l] + min(getdist(l, r), (long long)c) + rightmax[r];

            curans = max({curans, leftansmax[l], rightansmax[r]});

            for(int i = l; i <= r; i++){
                curans = max(curans, min(d[i] + getdist(l, i) + leftmax[l], d[i] + getdist(i, r) + c + leftmax[l]));
                curans = max(curans, min(d[i] + getdist(i, r) + rightmax[r], d[i] + getdist(l, i) + c + rightmax[r]));
            }

            for(int i = l; i <= r; i++){
                for(int j = i + 1; j <= r; j++){
                    curans = max(curans, min(d[i] + d[j] + getdist(i, j), d[i] + d[j] + getdist(l, i) + getdist(j, r) + c));
                }
            }

            ans = min(ans, curans);
        }
    }

    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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
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 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -