結果
問題 | No.409 ダイエット |
ユーザー | 0w1 |
提出日時 | 2019-10-17 14:22:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 2,421 bytes |
コンパイル時間 | 2,439 ms |
コンパイル使用メモリ | 217,080 KB |
実行使用メモリ | 7,864 KB |
最終ジャッジ日時 | 2024-06-24 10:19:39 |
合計ジャッジ時間 | 7,689 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 3 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 3 ms
6,940 KB |
testcase_37 | AC | 3 ms
6,940 KB |
testcase_38 | AC | 3 ms
6,940 KB |
testcase_39 | AC | 3 ms
6,940 KB |
testcase_40 | AC | 3 ms
6,944 KB |
testcase_41 | AC | 3 ms
6,944 KB |
testcase_42 | AC | 3 ms
6,940 KB |
testcase_43 | AC | 3 ms
6,940 KB |
testcase_44 | AC | 3 ms
6,944 KB |
testcase_45 | AC | 3 ms
6,940 KB |
testcase_46 | AC | 3 ms
6,940 KB |
testcase_47 | AC | 3 ms
6,940 KB |
testcase_48 | AC | 3 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,940 KB |
testcase_50 | AC | 3 ms
6,944 KB |
testcase_51 | AC | 3 ms
6,940 KB |
testcase_52 | AC | 3 ms
6,944 KB |
testcase_53 | AC | 3 ms
6,940 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 44 ms
6,940 KB |
testcase_56 | AC | 84 ms
7,596 KB |
testcase_57 | AC | 91 ms
7,764 KB |
testcase_58 | AC | 39 ms
6,940 KB |
testcase_59 | AC | 58 ms
6,940 KB |
testcase_60 | AC | 34 ms
6,944 KB |
testcase_61 | AC | 80 ms
7,244 KB |
testcase_62 | AC | 85 ms
7,428 KB |
testcase_63 | AC | 82 ms
7,348 KB |
testcase_64 | AC | 44 ms
6,940 KB |
testcase_65 | AC | 93 ms
7,400 KB |
testcase_66 | AC | 93 ms
7,864 KB |
testcase_67 | AC | 69 ms
6,944 KB |
testcase_68 | AC | 60 ms
6,940 KB |
testcase_69 | AC | 82 ms
7,200 KB |
testcase_70 | AC | 82 ms
6,944 KB |
testcase_71 | AC | 45 ms
6,944 KB |
testcase_72 | AC | 102 ms
7,736 KB |
testcase_73 | AC | 98 ms
7,264 KB |
testcase_74 | AC | 55 ms
6,940 KB |
testcase_75 | AC | 94 ms
7,400 KB |
testcase_76 | AC | 62 ms
6,940 KB |
testcase_77 | AC | 46 ms
6,944 KB |
testcase_78 | AC | 47 ms
6,940 KB |
testcase_79 | AC | 41 ms
6,940 KB |
testcase_80 | AC | 92 ms
7,420 KB |
testcase_81 | AC | 95 ms
7,256 KB |
testcase_82 | AC | 68 ms
6,940 KB |
testcase_83 | AC | 75 ms
6,944 KB |
testcase_84 | AC | 64 ms
6,940 KB |
testcase_85 | AC | 7 ms
6,940 KB |
testcase_86 | AC | 61 ms
6,940 KB |
testcase_87 | AC | 82 ms
6,940 KB |
testcase_88 | AC | 34 ms
6,944 KB |
testcase_89 | AC | 78 ms
6,944 KB |
testcase_90 | AC | 34 ms
6,940 KB |
testcase_91 | AC | 84 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename R> // return_type struct MongeDP { int n; vector<R> dp; vector<int> pre; function<bool(R, R)> cmp; // true is left better function<R(int, int)> w; MongeDP(int _n, function<bool(R, R)> c, function<R(int, int)> get_cost) : n(_n), dp(n + 1), pre(n + 1, -1), cmp(c), w(get_cost) { deque<tuple<int, int, int>> dcs; // decision dcs.emplace_back(0, 1, n); // transition from dp[0] is effective for [1, N] for (int i = 1; i <= n; ++i) { while (get<2>(dcs.front()) < i) dcs.pop_front(); // right bound is out-dated pre[i] = get<0>(dcs.front()); dp[i] = dp[pre[i]] + w(pre[i], i); // best t is A[dcs.top(), i) while (dcs.size()) { int x, lb, rb; tie(x, lb, rb) = dcs.back(); if (lb <= i) break; // will be pop_fronted soon anyway if (!cmp(dp[x] + w(x, lb), dp[i] + w(i, lb))) { dcs.pop_back(); if (dcs.size()) get<2>(dcs.back()) = n; } else break; } int best = -1; for (int lb = i + 1, rb = n, x = get<0>(dcs.back()); lb <= rb; ) { int mb = lb + rb >> 1; if (cmp(dp[i] + w(i, mb), dp[x] + w(x, mb))) { best = mb; rb = mb - 1; } else lb = mb + 1; } if (~best) { get<2>(dcs.back()) = best - 1; dcs.emplace_back(i, best, n); } } } void ensure_monge_condition() { // Monge Condition: i <= j <= k <= l then w(i, l) + w(j, k) >(<)= w(i, k) + w(j, l) for (int i = 0; i <= n; ++i) for (int j = i; j <= n; ++j) for (int k = j; k <= n; ++k) for (int l = k; l <= n; ++l) { R w0 = w(i, l), w1 = w(j, k), w2 = w(i, k), w3 = w(j, l); assert(w0 + w1 >= w2 + w3); // if maximization, revert the sign } } R operator[](int x) { return dp[x]; } }; signed main() { ios::sync_with_stdio(false); int N, A, B, W; cin >> N >> A >> B >> W; vector<int> D(N); for (int i = 0; i < N; ++i) { cin >> D[i]; } D.push_back(-A); ++N; MongeDP<int64_t> mdp(N, [](int64_t x, int64_t y) { return x < y; }, [&](int x, int rb) { int i = rb - 1 - x; return D[rb - 1] - (int64_t) i * A + (int64_t) i * (i + 1) / 2 * B; }); int64_t ans = W + A + mdp[N]; cout << ans << endl; return 0; }