結果
問題 | No.2332 Make a Sequence |
ユーザー | vwxyz |
提出日時 | 2023-08-10 18:40:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 989 ms / 2,000 ms |
コード長 | 3,342 bytes |
コンパイル時間 | 580 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 175,232 KB |
最終ジャッジ日時 | 2024-11-17 03:28:36 |
合計ジャッジ時間 | 34,940 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,608 KB |
testcase_01 | AC | 41 ms
52,352 KB |
testcase_02 | AC | 41 ms
52,992 KB |
testcase_03 | AC | 40 ms
53,120 KB |
testcase_04 | AC | 41 ms
52,480 KB |
testcase_05 | AC | 41 ms
52,864 KB |
testcase_06 | AC | 42 ms
52,864 KB |
testcase_07 | AC | 374 ms
159,896 KB |
testcase_08 | AC | 136 ms
102,144 KB |
testcase_09 | AC | 278 ms
123,892 KB |
testcase_10 | AC | 347 ms
141,304 KB |
testcase_11 | AC | 253 ms
125,616 KB |
testcase_12 | AC | 392 ms
158,216 KB |
testcase_13 | AC | 389 ms
157,828 KB |
testcase_14 | AC | 404 ms
158,092 KB |
testcase_15 | AC | 389 ms
158,220 KB |
testcase_16 | AC | 392 ms
157,832 KB |
testcase_17 | AC | 391 ms
161,288 KB |
testcase_18 | AC | 394 ms
158,344 KB |
testcase_19 | AC | 391 ms
158,208 KB |
testcase_20 | AC | 390 ms
157,836 KB |
testcase_21 | AC | 382 ms
158,092 KB |
testcase_22 | AC | 430 ms
151,440 KB |
testcase_23 | AC | 416 ms
151,328 KB |
testcase_24 | AC | 406 ms
151,428 KB |
testcase_25 | AC | 401 ms
151,688 KB |
testcase_26 | AC | 401 ms
151,252 KB |
testcase_27 | AC | 442 ms
151,772 KB |
testcase_28 | AC | 434 ms
151,428 KB |
testcase_29 | AC | 425 ms
151,176 KB |
testcase_30 | AC | 439 ms
151,172 KB |
testcase_31 | AC | 445 ms
151,532 KB |
testcase_32 | AC | 446 ms
148,672 KB |
testcase_33 | AC | 459 ms
148,744 KB |
testcase_34 | AC | 457 ms
148,608 KB |
testcase_35 | AC | 439 ms
148,612 KB |
testcase_36 | AC | 439 ms
148,108 KB |
testcase_37 | AC | 464 ms
158,976 KB |
testcase_38 | AC | 452 ms
156,800 KB |
testcase_39 | AC | 463 ms
159,256 KB |
testcase_40 | AC | 459 ms
156,172 KB |
testcase_41 | AC | 460 ms
159,168 KB |
testcase_42 | AC | 574 ms
159,484 KB |
testcase_43 | AC | 581 ms
159,112 KB |
testcase_44 | AC | 547 ms
156,548 KB |
testcase_45 | AC | 552 ms
157,560 KB |
testcase_46 | AC | 542 ms
158,340 KB |
testcase_47 | AC | 879 ms
166,668 KB |
testcase_48 | AC | 989 ms
166,788 KB |
testcase_49 | AC | 887 ms
166,800 KB |
testcase_50 | AC | 914 ms
166,408 KB |
testcase_51 | AC | 886 ms
166,804 KB |
testcase_52 | AC | 446 ms
156,468 KB |
testcase_53 | AC | 464 ms
154,476 KB |
testcase_54 | AC | 452 ms
152,060 KB |
testcase_55 | AC | 453 ms
156,412 KB |
testcase_56 | AC | 453 ms
156,536 KB |
testcase_57 | AC | 426 ms
150,016 KB |
testcase_58 | AC | 398 ms
147,736 KB |
testcase_59 | AC | 424 ms
149,852 KB |
testcase_60 | AC | 427 ms
155,264 KB |
testcase_61 | AC | 403 ms
152,160 KB |
testcase_62 | AC | 762 ms
175,232 KB |
ソースコード
import sys readline=sys.stdin.readline class Li_Chao_Tree: def __init__(self,N,X=None,inf=float("inf")): self.N=N if X==None: self.X=[x for x in range(self.N)] else: self.X=X self.idx={x:i for i,x in enumerate(self.X)} self.inf=inf self.li_chao_tree=[(0,self.inf)]*(2*self.N) self.left,self.right=[None]*2*N,[None]*2*N for i in range(self.N,2*self.N): self.left[i]=self.X[i-self.N] self.right[i]=self.X[i-self.N] for i in range(self.N-1,0,-1): self.left[i]=self.left[i<<1] self.right[i]=self.right[i<<1|1] def add_line_one_segment(self,a,b,i): queue=[i] while queue: i=queue.pop() aa,bb=self.li_chao_tree[i] l=a*self.X[self.left[i]]+b r=a*self.X[self.right[i]]+b ll=aa*self.X[self.left[i]]+bb rr=aa*self.X[self.right[i]]+bb if ll<=l and rr<=r: continue if l<=ll and r<=rr: self.li_chao_tree[i]=(a,b) continue queue.append(i<<1) queue.append(i<<1|1) def add_line(self,a,b,L=None,R=None): if L==None: L=self.N else: L+=self.N if R==None: R=2*self.N else: R+=self.N while L<R: if L%2: self.add_line_one_segment(a,b,L) L+=1 if R%2: R-=1 self.add_line_one_segment(a,b,R) L>>=1 R>>=1 def __call__(self,x): i=self.idx[x]+self.N retu=self.inf while i: a,b=self.li_chao_tree[i] retu=min(retu,a*x+b) i>>=1 return retu def __getitem__(self,i): x=self.X[i] i+=self.N retu=self.inf while i: a,b=self.li_chao_tree[i] retu=min(retu,a*x+b) i>>=1 return retu def __str__(self): li_chao_tree=[(0,inf)]*self.N for i,x in enumerate(self.X): ii=i+self.N while ii: aa,bb=self.li_chao_tree[ii] a,b=li_chao_tree[i] if aa*x+bb<a*x+b: li_chao_tree[i]=aa,bb ii>>=1 return "["+", ".join(map(str,li_chao_tree))+"]" def Z_algorithm(lst): le=len(lst) LCP=[None]*le LCP[0]=le L,R=0,0 for i in range(1,le): if i<R: x=LCP[i-L] if x<R-i: LCP[i]=x elif R-i<x: LCP[i]=R-i else: while R<le and lst[R-i]==lst[R]: R+=1 LCP[i]=R-i L=i else: R=max(R,i) while R<le and lst[R-i]==lst[R]: R+=1 LCP[i]=R-i L=i return LCP N,M=map(int,readline().split()) A=list(map(int,readline().split())) B=list(map(int,readline().split())) C=list(map(int,readline().split())) Z=Z_algorithm(A+B) inf=1<<60 LCT=Li_Chao_Tree(M+1,inf=inf) dp=[inf]*(M+1) dp[0]=0 for m in range(M): k=Z[N+m] LCT.add_line(C[m],dp[m]-m*C[m],m,m+k+1) dp[m+1]=LCT[m+1] if dp[M]==inf: ans=-1 else: ans=dp[M] print(ans)