結果
問題 |
No.31 悪のミックスジュース
|
ユーザー |
|
提出日時 | 2017-01-05 19:15:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 475,268 KB |
最終ジャッジ日時 | 2024-12-17 13:54:03 |
合計ジャッジ時間 | 69,832 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 TLE * 6 |
ソースコード
#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 = 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; }