結果

問題 No.31 悪のミックスジュース
ユーザー kimiyukikimiyuki
提出日時 2016-02-16 22:36:39
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,612 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 72,552 KB
最終ジャッジ日時 2024-04-16 19:10:10
合計ジャッジ時間 974 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:17: error: ‘accumulate’ was not declared in this scope
   27 |         cout << accumulate(c.begin(), c.end(), 0ll) << endl;
      |                 ^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
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;
    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]);
        }
    }
    if (v <= l) {
        cout << acc[n] + dp[v] << endl;
        return 0;
    }
    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