제출 #1034010

#제출 시각아이디문제언어결과실행 시간메모리
1034010fv3선물상자 (IOI15_boxes)C++14
50 / 100
2040 ms37460 KiB
#include "boxes.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF = 1ll << 60;

ll delivery(int N_, int K_, int L_, int p[])
{
    ll L = L_; ll N = N_; ll K = K_;

    vector<ll> v(N);
    for (int i = 0; i < N; i++)
        v[i] = p[i];
    sort(v.begin(), v.end());

    // Subtask 5: K <= 3000
    // Solve with Dynamic Programming

    // Let DP_r[i] be the minimum time to deliver the first i
    // packages and go back to start while only going right

    // Let DP_l[i] be the minimum time to deliver the last i
    // packages and go back to start while only going left

    // Find the optimal place to stop going right 
    vector<ll> DP_r(N + 1, INF), DP_l(N + 1, INF);
    DP_r[0] = 0; DP_l[N] = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j <= min(N, K + i); j++)
        {
            DP_r[j] = min({DP_r[j], DP_r[i] + v[j - 1] * 2, DP_r[i] + L});
        }
    }

    for (int i = N; i >= 1; i--)
    {
        for (int j = i - 1; j >= max(0ll, i - K); j--)
        {
            DP_l[j] = min({DP_l[j], DP_l[i] + (L - v[j]) * 2, DP_l[i] + L});
        }
    }

    ll res = INF;
    for (int i = 0; i <= N; i++)
        res = min(res, DP_r[i] + DP_l[i]);

    return res;
}

컴파일 시 표준 에러 (stderr) 메시지

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:39:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   39 |     for (int i = N; i >= 1; i--)
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...