結果
問題 | No.2332 Make a Sequence |
ユーザー | 👑 Nachia |
提出日時 | 2023-05-28 14:00:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 234 ms / 2,000 ms |
コード長 | 2,690 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 106,480 KB |
実行使用メモリ | 15,532 KB |
最終ジャッジ日時 | 2024-06-08 04:30:13 |
合計ジャッジ時間 | 11,060 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 65 ms
14,732 KB |
testcase_08 | AC | 23 ms
5,504 KB |
testcase_09 | AC | 52 ms
9,900 KB |
testcase_10 | AC | 51 ms
14,452 KB |
testcase_11 | AC | 36 ms
9,204 KB |
testcase_12 | AC | 77 ms
15,356 KB |
testcase_13 | AC | 80 ms
15,236 KB |
testcase_14 | AC | 73 ms
15,400 KB |
testcase_15 | AC | 77 ms
15,324 KB |
testcase_16 | AC | 79 ms
15,296 KB |
testcase_17 | AC | 80 ms
15,280 KB |
testcase_18 | AC | 79 ms
15,404 KB |
testcase_19 | AC | 80 ms
15,352 KB |
testcase_20 | AC | 80 ms
15,456 KB |
testcase_21 | AC | 78 ms
15,372 KB |
testcase_22 | AC | 78 ms
15,396 KB |
testcase_23 | AC | 77 ms
15,404 KB |
testcase_24 | AC | 80 ms
15,272 KB |
testcase_25 | AC | 74 ms
15,356 KB |
testcase_26 | AC | 74 ms
15,348 KB |
testcase_27 | AC | 77 ms
15,532 KB |
testcase_28 | AC | 81 ms
15,404 KB |
testcase_29 | AC | 75 ms
15,392 KB |
testcase_30 | AC | 78 ms
15,404 KB |
testcase_31 | AC | 75 ms
15,404 KB |
testcase_32 | AC | 85 ms
15,404 KB |
testcase_33 | AC | 84 ms
15,404 KB |
testcase_34 | AC | 86 ms
15,408 KB |
testcase_35 | AC | 85 ms
15,396 KB |
testcase_36 | AC | 82 ms
15,408 KB |
testcase_37 | AC | 85 ms
15,392 KB |
testcase_38 | AC | 84 ms
15,404 KB |
testcase_39 | AC | 92 ms
15,404 KB |
testcase_40 | AC | 86 ms
15,380 KB |
testcase_41 | AC | 82 ms
15,404 KB |
testcase_42 | AC | 120 ms
15,388 KB |
testcase_43 | AC | 121 ms
15,352 KB |
testcase_44 | AC | 116 ms
15,404 KB |
testcase_45 | AC | 119 ms
15,352 KB |
testcase_46 | AC | 124 ms
15,444 KB |
testcase_47 | AC | 223 ms
15,408 KB |
testcase_48 | AC | 234 ms
15,432 KB |
testcase_49 | AC | 228 ms
15,404 KB |
testcase_50 | AC | 218 ms
15,404 KB |
testcase_51 | AC | 227 ms
15,404 KB |
testcase_52 | AC | 80 ms
15,532 KB |
testcase_53 | AC | 80 ms
15,404 KB |
testcase_54 | AC | 78 ms
15,408 KB |
testcase_55 | AC | 80 ms
15,372 KB |
testcase_56 | AC | 83 ms
15,464 KB |
testcase_57 | AC | 75 ms
15,356 KB |
testcase_58 | AC | 80 ms
15,404 KB |
testcase_59 | AC | 80 ms
15,408 KB |
testcase_60 | AC | 81 ms
15,404 KB |
testcase_61 | AC | 77 ms
15,408 KB |
testcase_62 | AC | 165 ms
15,396 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <atcoder/modint> #include <atcoder/string> using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; struct LiChaoTree{ using Val = i64; struct Func { i64 a, b; Val operator()(i64 x) { return a * x + b; } }; static Func infFunc() { return { 0,INF }; } int N; vector<Func> V; vector<bool> visited; LiChaoTree(i64 n){ N = 1; while(N < n) N *= 2; V.assign(N*2, infFunc()); visited.assign(N*2, false); } void addSegment(i64 l, i64 r, Func f){ if(l >= r) return; auto dfs = [&,this](int i,Func f,i64 a,i64 b,auto dfs) -> void { visited[i] = true; if(i >= (i64)V.size()) return; if(r <= a || b <= l) return; i64 m = (a+b)/2; if(!(l <= a && b <= r)){ dfs(i*2,f,a,m,dfs); dfs(i*2+1,f,m,b,dfs); return; } bool greatf_l = !(V[i](a) < f(a)); bool greatf_r = !(V[i](b-1) < f(b-1)); if(!greatf_l && !greatf_r) return; if(greatf_l && greatf_r){ V[i] = f; return; } if(a + 1 == b) return; if(!(V[i](m) < f(m))){ swap(V[i],f); swap(greatf_l,greatf_r); } if(greatf_l) dfs(i*2,f,a,m,dfs); else dfs(i*2+1,f,m,b,dfs); }; dfs(1,f,0,N,dfs); } void addLine(Func f){ addSegment(0,N,f); } Val minVal(i64 p){ int i = 1; Val res = infFunc()(p); int l = 0, r = N; while(i < (i64)V.size()){ if(!visited[i]) break; res = min(res,V[i](p)); i64 m = (l+r)/2; if(p < m){ i = i*2; r = m; } else{ i = i*2+1; l = m; } } return res; } }; int main(){ int N, M; cin >> N >> M; vector<int> A(N); rep(i,N) cin >> A[i]; vector<int> B(M); rep(i,M) cin >> B[i]; vector<i64> C(M); rep(i,M) cin >> C[i]; vector<int> L(M); { vector<int> AB(N+M); rep(i,N) AB[i] = A[i]; rep(i,M) AB[N+i] = B[i]; auto Z = atcoder::z_algorithm(AB); rep(i,M) L[i] = min(Z[N+i], N); } LiChaoTree T(M+1); T.addSegment(0, 1, {0,0}); for(int l=0; l<M; l++){ if(L[l] == 0) continue; i64 cost = T.minVal(l); T.addSegment(l+1, l+L[l]+1, { C[l], cost-C[l]*l }); } i64 ans = T.minVal(M); if(ans == INF) ans = -1; cout << ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;