結果

問題 No.31 悪のミックスジュース
ユーザー PachicobuePachicobue
提出日時 2018-11-24 04:07:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,046 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 201,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 04:46:46
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 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() / 4;
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    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;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N * N; j++) { dp[j] = std::min(dp[j], dp[j - i - 1] + C[i]); }
    }
    if (V < N * N) { return std::cout << sum + dp[V] << std::endl, 0; }
    ll min = INF<ll>;
    for (int i = 0; i < N; i++) {
        const ll num = (V - N * N + i) / (i + 1);
        min = std::min(min, dp[V - num * (i + 1)] + num * C[i]);
    }
    std::cout << min + sum << std::endl;
    return 0;
}
0