結果
問題 | No.2332 Make a Sequence |
ユーザー | kotatsugame |
提出日時 | 2023-05-28 14:51:19 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 339 ms / 2,000 ms |
コード長 | 3,202 bytes |
コンパイル時間 | 1,994 ms |
コンパイル使用メモリ | 96,472 KB |
実行使用メモリ | 27,608 KB |
最終ジャッジ日時 | 2024-06-08 06:20:32 |
合計ジャッジ時間 | 22,966 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 263 ms
23,492 KB |
testcase_08 | AC | 73 ms
5,704 KB |
testcase_09 | AC | 201 ms
18,260 KB |
testcase_10 | AC | 212 ms
22,744 KB |
testcase_11 | AC | 141 ms
15,960 KB |
testcase_12 | AC | 315 ms
27,472 KB |
testcase_13 | AC | 322 ms
27,604 KB |
testcase_14 | AC | 323 ms
27,604 KB |
testcase_15 | AC | 318 ms
27,472 KB |
testcase_16 | AC | 322 ms
27,480 KB |
testcase_17 | AC | 318 ms
27,608 KB |
testcase_18 | AC | 315 ms
27,480 KB |
testcase_19 | AC | 311 ms
27,604 KB |
testcase_20 | AC | 307 ms
27,604 KB |
testcase_21 | AC | 315 ms
27,416 KB |
testcase_22 | AC | 306 ms
27,568 KB |
testcase_23 | AC | 299 ms
27,352 KB |
testcase_24 | AC | 312 ms
27,476 KB |
testcase_25 | AC | 301 ms
27,472 KB |
testcase_26 | AC | 304 ms
27,472 KB |
testcase_27 | AC | 317 ms
27,092 KB |
testcase_28 | AC | 307 ms
27,096 KB |
testcase_29 | AC | 306 ms
27,088 KB |
testcase_30 | AC | 307 ms
27,092 KB |
testcase_31 | AC | 313 ms
26,968 KB |
testcase_32 | AC | 306 ms
25,680 KB |
testcase_33 | AC | 311 ms
25,680 KB |
testcase_34 | AC | 312 ms
25,684 KB |
testcase_35 | AC | 306 ms
25,808 KB |
testcase_36 | AC | 307 ms
25,684 KB |
testcase_37 | AC | 316 ms
26,712 KB |
testcase_38 | AC | 316 ms
26,836 KB |
testcase_39 | AC | 314 ms
26,712 KB |
testcase_40 | AC | 316 ms
26,708 KB |
testcase_41 | AC | 315 ms
26,888 KB |
testcase_42 | AC | 320 ms
25,428 KB |
testcase_43 | AC | 314 ms
25,560 KB |
testcase_44 | AC | 333 ms
25,688 KB |
testcase_45 | AC | 325 ms
25,936 KB |
testcase_46 | AC | 327 ms
25,556 KB |
testcase_47 | AC | 316 ms
24,408 KB |
testcase_48 | AC | 315 ms
24,408 KB |
testcase_49 | AC | 320 ms
24,400 KB |
testcase_50 | AC | 326 ms
24,272 KB |
testcase_51 | AC | 323 ms
24,276 KB |
testcase_52 | AC | 316 ms
26,968 KB |
testcase_53 | AC | 318 ms
26,960 KB |
testcase_54 | AC | 314 ms
26,968 KB |
testcase_55 | AC | 315 ms
27,092 KB |
testcase_56 | AC | 318 ms
26,968 KB |
testcase_57 | AC | 231 ms
10,196 KB |
testcase_58 | AC | 227 ms
8,788 KB |
testcase_59 | AC | 223 ms
9,172 KB |
testcase_60 | AC | 233 ms
9,556 KB |
testcase_61 | AC | 231 ms
8,788 KB |
testcase_62 | AC | 339 ms
25,684 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:132:9: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized] 132 | if(ans==(long)1e18)ans=-1; | ^~ main.cpp:121:14: note: 'ans' was declared here 121 | long ans; | ^~~
ソースコード
#include<iostream> #include<vector> #include<queue> #include<atcoder/string> using namespace std; /** * @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 N,M; int A[2<<17],B[2<<17],C[2<<17]; int main() { cin>>N>>M; vector<int>S; for(int i=0;i<N;i++) { cin>>A[i]; S.push_back(A[i]); } for(int i=0;i<M;i++) { cin>>B[i]; S.push_back(B[i]); } for(int i=0;i<M;i++)cin>>C[i]; vector<int>T=atcoder::z_algorithm(S); DynamicLiChaoTree<long,0L,(long)2e5,(long)1e18>Q; Q.add_segment(0,1,0,0); long ans; for(int i=0;i<=M;i++) { ans=Q.query(i); if(i<M&&ans<(long)1e18) { int len=min(T[N+i],N); //cout<<i<<"->"<<i+len<<" : "<<ans+C[i]<<endl; Q.add_segment(i,i+len+1,C[i],ans-(long)i*C[i]); } } if(ans==(long)1e18)ans=-1; cout<<ans<<endl; }