結果
| 問題 |
No.31 悪のミックスジュース
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-01-05 19:17:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3,252 ms / 5,000 ms |
| コード長 | 1,030 bytes |
| コンパイル時間 | 742 ms |
| コンパイル使用メモリ | 82,684 KB |
| 実行使用メモリ | 143,972 KB |
| 最終ジャッジ日時 | 2024-12-17 13:55:44 |
| 合計ジャッジ時間 | 36,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#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 = 1.2e7; // ???
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;
}