結果
問題 | No.409 ダイエット |
ユーザー |
|
提出日時 | 2016-10-20 03:44:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 711 ms |
コンパイル使用メモリ | 79,928 KB |
実行使用メモリ | 6,692 KB |
最終ジャッジ日時 | 2024-06-26 10:01:59 |
合計ジャッジ時間 | 5,715 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 92 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <cmath>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)typedef long long ll;using namespace std;template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }const ll inf = ll(1e18)+9;int main() {// inputint n, a, b, w; cin >> n >> a >> b >> w;vector<int> d(n); repeat (i,n) cin >> d[i];if (b == 0) {// outputcout << w - a*(ll)n << endl;} else {// dpn += 1;d.push_back(0);int limit = 2 * sqrt((*whole(max_element, d) + a) / b) + 3;vector<ll> dp(n+1);dp[0] = w;repeat (i,n) {ll acc = inf;repeat_reverse (j,i+1) {setmin(acc, dp[j] - a *(ll) ll(i-j) + b *(ll) (i-j)*(i-j+1)/2);if (i-j > limit) break;}dp[i+1] = acc + d[i];}// outputcout << dp[n] << endl;}return 0;}