結果
問題 | No.409 ダイエット |
ユーザー | はまやんはまやん |
提出日時 | 2017-03-24 16:15:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,993 bytes |
コンパイル時間 | 1,657 ms |
コンパイル使用メモリ | 173,136 KB |
実行使用メモリ | 7,248 KB |
最終ジャッジ日時 | 2024-07-06 01:56:52 |
合計ジャッジ時間 | 5,163 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 3 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | AC | 32 ms
7,112 KB |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | WA | - |
testcase_72 | WA | - |
testcase_73 | WA | - |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | WA | - |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | WA | - |
testcase_89 | WA | - |
testcase_90 | WA | - |
testcase_91 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) typedef long double ld; template<typename T> struct CHT { struct line { T slope, xterm; inline T get(const int x) const { return slope * x + xterm; } }; deque<line> lines; inline ld area(const line& a, const line& b, const line& c) { ld ax = (b.slope - a.slope); ld bx = (c.xterm - a.xterm); ld ay = (c.slope - a.slope); ld by = (b.xterm - a.xterm); return ax * bx - ay * by; } inline bool cw(const line& a, const line& b, const line& c) { return area(a, b, c) < 0; } void add(T a, T b) { line l; l.slope = a, l.xterm = b; while (lines.size() > 1 && cw(lines[lines.size() - 2], lines[lines.size() - 1], l)) lines.pop_back(); if (lines.size() == 1) { if (lines.front().xterm > l.xterm) lines.push_back(l); } else lines.push_back(l); } T get(int x) { if (lines.empty()) return 0; while (lines.size() > 1 && lines[0].get(x) > lines[1].get(x)) lines.pop_front(); return lines[0].get(x); } }; //----------------------------------------------------------------------------------- typedef long long ll; #define INF 1LL<<60 int N, A, B, W; int D[301010]; //----------------------------------------------------------------------------------- ll dp[301010]; int main() { cin >> N >> A >> B >> W; rep(i, 0, N) scanf("%d", &D[i]); /* Naive dp[0] = W; rep(i, 1, N + 1) { dp[i] = INF; rep(j, 0, i) { ll w = dp[j]; w -= 1LL * A * (i - j - 1); w += 1LL * (i - j - 1) * (i - j) / 2 * B; dp[i] = min(dp[i], w); } dp[i] += D[i - 1]; } */ // Optimized CHT<ll> cht; dp[0] = W; cht.add(0, W); rep(i, 1, N + 1) { dp[i] = cht.get(i) - 1LL * (i - 1) * A + (1LL * (i - 1) * i) / 2 * B + D[i - 1]; cht.add(-1LL * B * i, dp[i] + 1LL * A * i + (1LL * i * i + i) / 2 * B); } ll ans = INF; rep(i, 0, N + 1) { ll w = dp[i]; int n = N - i; w -= 1LL * A * n; w += 1LL * n * (n + 1) / 2 * B; ans = min(ans, w); } cout << ans << endl; }