結果
問題 | No.2332 Make a Sequence |
ユーザー | Kude |
提出日時 | 2023-05-28 15:25:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 211 ms / 2,000 ms |
コード長 | 4,126 bytes |
コンパイル時間 | 2,557 ms |
コンパイル使用メモリ | 230,732 KB |
実行使用メモリ | 27,776 KB |
最終ジャッジ日時 | 2024-06-08 07:43:23 |
合計ジャッジ時間 | 15,677 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 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 | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 129 ms
23,680 KB |
testcase_08 | AC | 26 ms
6,144 KB |
testcase_09 | AC | 101 ms
18,560 KB |
testcase_10 | AC | 115 ms
23,168 KB |
testcase_11 | AC | 84 ms
16,256 KB |
testcase_12 | AC | 160 ms
27,648 KB |
testcase_13 | AC | 160 ms
27,776 KB |
testcase_14 | AC | 176 ms
27,648 KB |
testcase_15 | AC | 164 ms
27,776 KB |
testcase_16 | AC | 167 ms
27,776 KB |
testcase_17 | AC | 160 ms
27,648 KB |
testcase_18 | AC | 158 ms
27,648 KB |
testcase_19 | AC | 152 ms
27,520 KB |
testcase_20 | AC | 155 ms
27,648 KB |
testcase_21 | AC | 155 ms
27,648 KB |
testcase_22 | AC | 152 ms
27,648 KB |
testcase_23 | AC | 155 ms
27,520 KB |
testcase_24 | AC | 152 ms
27,520 KB |
testcase_25 | AC | 154 ms
27,520 KB |
testcase_26 | AC | 162 ms
27,520 KB |
testcase_27 | AC | 157 ms
27,392 KB |
testcase_28 | AC | 151 ms
27,264 KB |
testcase_29 | AC | 150 ms
27,264 KB |
testcase_30 | AC | 155 ms
27,264 KB |
testcase_31 | AC | 156 ms
27,264 KB |
testcase_32 | AC | 161 ms
25,856 KB |
testcase_33 | AC | 158 ms
25,984 KB |
testcase_34 | AC | 150 ms
25,856 KB |
testcase_35 | AC | 147 ms
25,984 KB |
testcase_36 | AC | 157 ms
25,984 KB |
testcase_37 | AC | 156 ms
26,880 KB |
testcase_38 | AC | 160 ms
26,880 KB |
testcase_39 | AC | 162 ms
26,880 KB |
testcase_40 | AC | 152 ms
27,008 KB |
testcase_41 | AC | 149 ms
27,008 KB |
testcase_42 | AC | 152 ms
25,600 KB |
testcase_43 | AC | 164 ms
25,728 KB |
testcase_44 | AC | 167 ms
25,856 KB |
testcase_45 | AC | 159 ms
26,112 KB |
testcase_46 | AC | 162 ms
25,856 KB |
testcase_47 | AC | 202 ms
24,448 KB |
testcase_48 | AC | 209 ms
24,448 KB |
testcase_49 | AC | 211 ms
24,448 KB |
testcase_50 | AC | 207 ms
24,320 KB |
testcase_51 | AC | 211 ms
24,320 KB |
testcase_52 | AC | 148 ms
27,264 KB |
testcase_53 | AC | 154 ms
27,264 KB |
testcase_54 | AC | 152 ms
27,264 KB |
testcase_55 | AC | 154 ms
27,136 KB |
testcase_56 | AC | 158 ms
27,136 KB |
testcase_57 | AC | 77 ms
10,496 KB |
testcase_58 | AC | 71 ms
8,960 KB |
testcase_59 | AC | 73 ms
9,216 KB |
testcase_60 | AC | 73 ms
9,856 KB |
testcase_61 | AC | 73 ms
8,960 KB |
testcase_62 | AC | 183 ms
25,856 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; // https://ei1333.github.io/library/structure/convex-hull-trick/dynamic-li-chao-tree.hpp /** * @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); int n, m; cin >> n >> m; VI a(n), b(m), c(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; rep(i, m) cin >> c[i]; VI ab(n + m + 1); rep(i, n) ab[i] = a[i]; ab[n] = -1; rep(i, m) ab[n + 1 + i] = b[i]; auto len = z_algorithm(ab); len.erase(len.begin(), len.begin() + n + 1); // rep(i, m) cout << len[i] << " \n"[i + 1 == m]; constexpr long long INF = 1002003004005006007; DynamicLiChaoTree<ll, 0, 200010, INF> dp; dp.add_segment(0, 1, 0, 0); for(int i = 0; i <= m; i++) { ll v = dp.query(i); if (v == INF) { cout << -1 << '\n'; break; } if (i == m) { cout << v << '\n'; break; } // ci(x-i) + v dp.add_segment(i, i + len[i] + 1, c[i], v - (ll)i * c[i]); } exit(0); }