結果
問題 | No.409 ダイエット |
ユーザー | miyo2580 |
提出日時 | 2023-10-06 23:09:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 3,526 bytes |
コンパイル時間 | 2,079 ms |
コンパイル使用メモリ | 205,500 KB |
実行使用メモリ | 20,224 KB |
最終ジャッジ日時 | 2024-07-26 16:55:46 |
合計ジャッジ時間 | 7,848 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 1 ms
6,944 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,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 3 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,944 KB |
testcase_41 | AC | 3 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 3 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 3 ms
6,948 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 | 3 ms
6,944 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 | 2 ms
6,944 KB |
testcase_54 | AC | 3 ms
6,944 KB |
testcase_55 | AC | 45 ms
11,136 KB |
testcase_56 | AC | 22 ms
7,680 KB |
testcase_57 | AC | 91 ms
19,968 KB |
testcase_58 | AC | 42 ms
10,624 KB |
testcase_59 | AC | 56 ms
11,520 KB |
testcase_60 | AC | 38 ms
9,728 KB |
testcase_61 | AC | 81 ms
17,536 KB |
testcase_62 | AC | 88 ms
18,944 KB |
testcase_63 | AC | 79 ms
17,024 KB |
testcase_64 | AC | 42 ms
10,240 KB |
testcase_65 | AC | 80 ms
14,336 KB |
testcase_66 | AC | 91 ms
18,560 KB |
testcase_67 | AC | 69 ms
15,872 KB |
testcase_68 | AC | 54 ms
11,520 KB |
testcase_69 | AC | 79 ms
16,384 KB |
testcase_70 | AC | 81 ms
16,768 KB |
testcase_71 | AC | 45 ms
10,880 KB |
testcase_72 | AC | 98 ms
20,224 KB |
testcase_73 | AC | 88 ms
15,872 KB |
testcase_74 | AC | 58 ms
12,672 KB |
testcase_75 | AC | 93 ms
16,512 KB |
testcase_76 | AC | 66 ms
14,208 KB |
testcase_77 | AC | 44 ms
8,832 KB |
testcase_78 | AC | 51 ms
11,776 KB |
testcase_79 | AC | 40 ms
9,728 KB |
testcase_80 | AC | 95 ms
18,688 KB |
testcase_81 | AC | 87 ms
16,256 KB |
testcase_82 | AC | 67 ms
14,464 KB |
testcase_83 | AC | 71 ms
14,976 KB |
testcase_84 | AC | 57 ms
10,752 KB |
testcase_85 | AC | 9 ms
6,940 KB |
testcase_86 | AC | 56 ms
11,264 KB |
testcase_87 | AC | 85 ms
17,024 KB |
testcase_88 | AC | 33 ms
7,936 KB |
testcase_89 | AC | 56 ms
8,448 KB |
testcase_90 | AC | 28 ms
6,940 KB |
testcase_91 | AC | 61 ms
8,832 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (ll i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; typedef pair<ll,ll> P; typedef vector<ll> vec; using Graph = vector<vector<ll>>; const long long INF = (1LL << 62) - 1; const long long MOD = 1000000007; /** * @brief Dynamic-Li-Chao-Tree * @docs docs/dynamic-li-chao-tree.md */ template< typename T, T x_low, T x_high, T id > struct DynamicLiChaoTree { struct Line { T a, b; Line(T a, T b) : a(a), b(b) {} inline T get(T 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() : root{nullptr} {} Node *add_line(Node *t, Line &x, const T &l, const T &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 { T 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 T &a, const T &b, const T &l, const T &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)); } T 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 T &l, const T &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 T &l, const T &r, const T &x) const { if(!t) return id; if(l == r) return t->x.get(x); T 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() { ios::sync_with_stdio(false); cin.tie(0); ll n,a,b,w; cin>>n>>a>>b>>w; vec d(n); rep(i,n)cin>>d[i]; vec dp(n+1,INF); dp[0]=0; DynamicLiChaoTree<ll,0,300005,INF> cht; rep(i,n){ dp[i]=b*(i)*(i+1)/2-a*(i)+d[i]; if(i)chmin(dp[i],cht.query(i)+(i)*(i+1)*b/2-a*(i)+d[i]); cht.add_line(-(i+1)*b,i*(i+1)*b/2+a*(i+1)+dp[i]); } ll ans=b*(n)*(n+1)/2-a*n; chmin(ans,cht.query(n)+n*(n+1)*b/2-a*n); cout<<ans+w<<endl; return 0; }