結果
問題 | No.409 ダイエット |
ユーザー | Coki628 |
提出日時 | 2020-12-24 01:06:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 117 ms / 2,000 ms |
コード長 | 6,308 bytes |
コンパイル時間 | 2,498 ms |
コンパイル使用メモリ | 210,436 KB |
実行使用メモリ | 20,116 KB |
最終ジャッジ日時 | 2024-09-21 16:40:28 |
合計ジャッジ時間 | 8,130 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 3 ms
5,376 KB |
testcase_37 | AC | 3 ms
5,376 KB |
testcase_38 | AC | 3 ms
5,376 KB |
testcase_39 | AC | 3 ms
5,376 KB |
testcase_40 | AC | 3 ms
5,376 KB |
testcase_41 | AC | 3 ms
5,376 KB |
testcase_42 | AC | 3 ms
5,376 KB |
testcase_43 | AC | 3 ms
5,376 KB |
testcase_44 | AC | 3 ms
5,376 KB |
testcase_45 | AC | 3 ms
5,376 KB |
testcase_46 | AC | 3 ms
5,376 KB |
testcase_47 | AC | 3 ms
5,376 KB |
testcase_48 | AC | 3 ms
5,376 KB |
testcase_49 | AC | 3 ms
5,376 KB |
testcase_50 | AC | 3 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 3 ms
5,376 KB |
testcase_53 | AC | 3 ms
5,376 KB |
testcase_54 | AC | 3 ms
5,376 KB |
testcase_55 | AC | 52 ms
11,052 KB |
testcase_56 | AC | 27 ms
7,552 KB |
testcase_57 | AC | 110 ms
20,036 KB |
testcase_58 | AC | 46 ms
10,404 KB |
testcase_59 | AC | 64 ms
11,468 KB |
testcase_60 | AC | 42 ms
9,528 KB |
testcase_61 | AC | 94 ms
17,452 KB |
testcase_62 | AC | 104 ms
18,992 KB |
testcase_63 | AC | 96 ms
16,908 KB |
testcase_64 | AC | 48 ms
10,228 KB |
testcase_65 | AC | 95 ms
14,316 KB |
testcase_66 | AC | 106 ms
18,452 KB |
testcase_67 | AC | 81 ms
15,604 KB |
testcase_68 | AC | 64 ms
11,568 KB |
testcase_69 | AC | 93 ms
16,232 KB |
testcase_70 | AC | 95 ms
16,640 KB |
testcase_71 | AC | 52 ms
10,584 KB |
testcase_72 | AC | 117 ms
20,116 KB |
testcase_73 | AC | 105 ms
15,584 KB |
testcase_74 | AC | 66 ms
12,768 KB |
testcase_75 | AC | 103 ms
16,488 KB |
testcase_76 | AC | 76 ms
14,124 KB |
testcase_77 | AC | 48 ms
8,988 KB |
testcase_78 | AC | 60 ms
11,848 KB |
testcase_79 | AC | 46 ms
9,696 KB |
testcase_80 | AC | 109 ms
18,716 KB |
testcase_81 | AC | 103 ms
16,076 KB |
testcase_82 | AC | 78 ms
14,276 KB |
testcase_83 | AC | 86 ms
14,652 KB |
testcase_84 | AC | 66 ms
10,896 KB |
testcase_85 | AC | 8 ms
5,376 KB |
testcase_86 | AC | 65 ms
11,240 KB |
testcase_87 | AC | 95 ms
16,900 KB |
testcase_88 | AC | 37 ms
7,740 KB |
testcase_89 | AC | 66 ms
8,540 KB |
testcase_90 | AC | 32 ms
6,168 KB |
testcase_91 | AC | 71 ms
8,900 KB |
ソースコード
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pii = pair<int, int>; using vvl = vector<vector<ll>>; using vvi = vector<vector<int>>; using vvpll = vector<vector<pll>>; #define rep(i, a, b) for (ll i=(a); i<(b); i++) #define rrep(i, a, b) for (ll i=(a); i>(b); i--) #define pb push_back #define tostr to_string #define ALL(A) A.begin(), A.end() constexpr ll INF = LONG_LONG_MAX; constexpr ll MOD = 1000000007; template<typename T> vector<vector<T>> list2d(int N, int M, T init) { vector<vector<T>> res(N, vector<T>(M, init)); return res; } template<typename T> vector<vector<vector<T>>> list3d(int N, int M, int L, T init) { vector<vector<vector<T>>> res(N, vector<vector<T>>(M, vector<T>(L, init))); return res; } void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; } void print(double out) { cout << fixed << setprecision(15) << out << '\n'; } template<typename T> void print(T out) { cout << out << '\n'; } template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; } template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } } template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); } void Yes() { print("Yes"); } void No() { print("No"); } void YES() { print("YES"); } void NO() { print("NO"); } ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } } ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } } pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; } template<typename T> bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; } template<typename T> bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; } template<typename T> T sum(vector<T> A) { T res = 0; for (T a: A) res += a; return res; } template<typename T> T max(vector<T> A) { return *max_element(ALL(A)); } template<typename T> T min(vector<T> A) { return *min_element(ALL(A)); } ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; } int toint(char num) { return num - '0'; } char tochar(int num) { return '0' + num; } int ord(char c) { return (int)c; } char chr(int a) { return (char)a; } ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; } ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } int popcount(ll S) { return __builtin_popcountll(S); } ll gcd(ll a, ll b) { return __gcd(a, b); } template<typename T> int bisect_left(vector<T> A, T val) { return lower_bound(ALL(A), val) - A.begin(); } template<typename T> int bisect_right(vector<T> A, T val) { return upper_bound(ALL(A), val) - A.begin(); } // Li Chao Tree template<typename T> struct DynamicLiChaoTree { const ll x_low; const ll x_high; const T id; struct Line { T a, b; Line(T a, T b) : a(a), b(b) {} inline T get(ll x) const { return a * x + b; } }; struct Node { Line x; Node *l, *r; Node(const Line &x) : x{x}, l{nullptr}, r{nullptr} {} }; Node *root; DynamicLiChaoTree(ll x_low, ll x_high, T id) : root{nullptr}, x_low(x_low), x_high(x_high), id(id) {} Node *add_line(Node *t, Line &x, const ll &l, const ll &r, const T &x_l, const T &x_r) { if(!t) return new Node(x); T t_l = t->x.get(l), t_r = t->x.get(r); if(t_l <= x_l && t_r <= x_r) { return t; } else if(t_l >= x_l && t_r >= x_r) { t->x = x; return t; } else { ll m = (l + r) / 2; if(m == r) --m; T t_m = t->x.get(m), x_m = x.get(m); if(t_m > x_m) { swap(t->x, x); if(x_l >= t_l) t->l = add_line(t->l, x, l, m, t_l, t_m); else t->r = add_line(t->r, x, m + 1, r, t_m + x.a, t_r); } else { if(t_l >= x_l) t->l = add_line(t->l, x, l, m, x_l, x_m); else t->r = add_line(t->r, x, m + 1, r, x_m + x.a, x_r); } return t; } } void add_line(const T &a, const T &b) { Line x(a, b); root = add_line(root, x, x_low, x_high, x.get(x_low), x.get(x_high)); } Node *add_segment(Node *t, Line &x, const ll &a, const ll &b, const ll &l, const ll &r, const T &x_l, const T &x_r) { if(r < a || b < l) return t; if(a <= l && r <= b) { Line y{x}; return add_line(t, y, l, r, x_l, x_r); } if(t) { T t_l = t->x.get(l), t_r = t->x.get(r); if(t_l <= x_l && t_r <= x_r) return t; } else { t = new Node(Line(0, id)); } ll m = (l + r) / 2; if(m == r) --m; T x_m = x.get(m); t->l = add_segment(t->l, x, a, b, l, m, x_l, x_m); t->r = add_segment(t->r, x, a, b, m + 1, r, x_m + x.a, x_r); return t; } void add_segment(const ll &l, const ll &r, const T &a, const T &b) { Line x(a, b); root = add_segment(root, x, l, r - 1, x_low, x_high, x.get(x_low), x.get(x_high)); } T query(const Node *t, const ll &l, const ll &r, const T &x) const { if(!t) return id; if(l == r) return t->x.get(x); ll m = (l + r) / 2; if(m == r) --m; if(x <= m) return min(t->x.get(x), query(t->l, l, m, x)); else return min(t->x.get(x), query(t->r, m + 1, r, x)); } T query(const T &x) const { return query(root, x_low, x_high, x); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, A, B, W; cin >> N >> A >> B >> W; vector<ll> D(N); rep(i, 0, N) cin >> D[i]; D.insert(D.begin(), 0); vector<ll> dp(N+1); DynamicLiChaoTree<ll> lct(0, N+1, INF); dp[0] = W; lct.add_line(0, dp[0]); rep(i, 1, N+1) { lct.add_line(-i*B, dp[i-1]+D[i] + (i*i-i)/2*B + A*i); dp[i] = lct.query(i) + (i*i+i)/2*B - A*i; } ll ans = dp[N]; print(ans); return 0; }