結果

問題 No.31 悪のミックスジュース
ユーザー kyunakyuna
提出日時 2019-08-08 00:48:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 836 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 72,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 23:20:39
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, v; cin >> n >> v;
    vector<long long> c(n);
    for (auto &ci: c) cin >> ci;
    v = max(0, v - n);
    vector<long long> acc(n + 1);
    for (int k = 0; k < n; k++) acc[k + 1] = acc[k] + c[k];
    int opt = 1;
    for (int k = 2; k <= n; k++) if (acc[opt] * k > acc[k] * opt) opt = k;
    vector<long long> dp(n * n + 1, INF);
    dp[0] = 0;
    for (int k = 1; k <= n; k++) {
        for (int i = k; i <= n * n; i++) chmin(dp[i], dp[i - k] + acc[k]);
    }
    int m = max(0, (v - n * n + n) / opt);
    long long res = acc[opt] * m + dp[v - m * opt] + acc[n];
    cout << res << endl;
    return 0;
}
0