結果

問題 No.31 悪のミックスジュース
ユーザー kimiyukikimiyuki
提出日時 2016-07-04 12:12:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,050 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 120,516 KB
最終ジャッジ日時 2024-04-28 15:44:15
合計ジャッジ時間 17,646 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1,348 ms
75,324 KB
testcase_02 AC 1,341 ms
78,188 KB
testcase_03 AC 2,295 ms
120,388 KB
testcase_04 AC 1,131 ms
120,388 KB
testcase_05 AC 1,116 ms
120,388 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2,029 ms
120,428 KB
testcase_08 AC 1,938 ms
120,388 KB
testcase_09 AC 2,329 ms
120,516 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 509 ms
36,952 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1,627 ms
108,664 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <climits>
#include <cmath>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll; 
using namespace std;
int main() {
    int n; ll v; cin >> n >> v;
    vector<ll> c(n); repeat (i,n) cin >> c[i];
    if (v <= n) {
        cout << accumulate(c.begin(), c.end(), 0ll) << endl;
        return 0;
    }   
    v -= n; // the restriction, that all fruits must be used, is fulfilled now.
    vector<ll> acc(n+1); repeat (i,n) acc[i+1] = acc[i] + c[i];
    const int l = n*n*n*sqrt(n); // ??? 
    vector<ll> dp(l+1, LLONG_MAX);
    dp[0] = 0;
    repeat (i,l) {
        repeat (j,min(i+1,n)) {
            dp[i+1] = min(dp[i+1], dp[i-j] + acc[j+1]);
        }   
    }   
    vector<int> eff(l); repeat (i,l) eff[i] = i+1;
    sort(eff.begin(), eff.end(), [&](int a, int b) {
        return dp[a] * b < dp[b] * a; // sort by the efficiency
    }); 
    int e = eff.front();
    cout << acc[n] + (v / e) * dp[e] + dp[v % e] << endl;
    return 0;
}
0