結果

問題 No.31 悪のミックスジュース
ユーザー PachicobuePachicobue
提出日時 2018-11-24 03:45:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 4,002 ms
コンパイル使用メモリ 202,944 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 04:46:27
合計ジャッジ時間 3,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 14 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
int main()
{
    int N;
    ll V;
    std::cin >> N >> V;
    std::vector<ll> C(N);
    ll sum = 0;
    for (auto& e : C) { std::cin >> e, sum += e, V--; }
    if (V <= 0) { return std::cout << sum << std::endl, 0; }
    for (int i = 1; i < N; i++) { C[i] += C[i - 1]; }
    std::vector<ll> dp(N * N, INF<ll>);  // 合計iリットル使う最安値
    dp[0] = 0;
    std::vector<ll> tmp(N * N, INF<ll>);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N * N; j++) { tmp[j] = (j <= i ? dp[j] : std::min(dp[j], tmp[j - i - 1] + C[i])); }
        std::swap(dp, tmp), std::fill(tmp.begin(), tmp.end(), INF<ll>);
    }
    ll min = INF<ll>;
    for (int i = 0; i < N * N; i++) {
        for (int j = 0; j < N; j++) { min = std::min(min, dp[i] + std::max(0LL, (V - i + j) / (j + 1) * C[j])); }
    }
    std::cout << min + sum << std::endl;
    return 0;
}
0