답안 #591762

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

using namespace std;

const long long INF = 1e9 + 5;

vector<long long> prefix, leftmax, rightmax;

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);

    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]); 
    for(int i = n; i >= 1; i--) rightmax[i] = max(rightmax[i + 1] + ln[i], (long long)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];

            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]));
            }

            int ptr = l + 1;

            for(int i = l; i <= r; i++){
                while(ptr + 1 <= r && min(getdist(i, ptr + 1) + d[i] + d[ptr +1], getdist(l, i) + c + getdist(ptr +1, r) + d[i] + d[ptr +1]) >= min(getdist(i, ptr) + d[i] + d[ptr], getdist(l, i) + c + getdist(ptr, r) + d[i] + d[ptr])){
                    ptr++;
                }

                curans = max(curans, min(getdist(i, ptr) + d[i] + d[ptr], getdist(l, i) + c + getdist(ptr, r) + d[i] + d[ptr]));
            }

            ans = min(ans, curans);
        }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 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 1 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 0 ms 212 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 300 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -