結果

問題 No.31 悪のミックスジュース
ユーザー mamekinmamekin
提出日時 2015-01-12 21:03:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,217 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 90,000 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 17:14:21
合計ジャッジ時間 1,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n, v;
    cin >> n >> v;
    vector<long long> c(n), sum(n+1, 0);
    for(int i=0; i<n; ++i){
        cin >> c[i];
        sum[i+1] = sum[i] + c[i];
    }
    if(v <= n){
        cout << sum[n] << endl;
        return 0;
    }

    vector<long long> dp(20001, LLONG_MAX);
    dp[0] = 0;
    for(int i=0; i<20000; ++i){
        for(int j=1; j<=n; ++j){
            if(i+j <= 20000)
                dp[i+j] = min(dp[i+j], dp[i] + sum[j]);
        }
    }

    if(v <= 20000){
        long long ret = sum[n] + dp[v-n];
        cout << ret << endl;
        return 0;
    }

    int m = v - n - 15000;
    long long ret = LLONG_MAX;
    for(int i=1; i<=n; ++i){
        int a = m / i;
        int b = 15000 + m % i;
        ret = min(ret, sum[n] + sum[i] * a + dp[b]);
    }
    cout << ret << endl;

    return 0;
}
0