結果
問題 | No.2332 Make a Sequence |
ユーザー | vwxyz |
提出日時 | 2023-08-10 18:54:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 939 ms / 2,000 ms |
コード長 | 3,349 bytes |
コンパイル時間 | 1,286 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 175,588 KB |
最終ジャッジ日時 | 2024-11-17 03:43:54 |
合計ジャッジ時間 | 37,226 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,992 KB |
testcase_01 | AC | 39 ms
52,864 KB |
testcase_02 | AC | 37 ms
52,864 KB |
testcase_03 | AC | 37 ms
52,864 KB |
testcase_04 | AC | 39 ms
52,992 KB |
testcase_05 | AC | 39 ms
52,992 KB |
testcase_06 | AC | 38 ms
52,736 KB |
testcase_07 | AC | 439 ms
162,824 KB |
testcase_08 | AC | 130 ms
102,400 KB |
testcase_09 | AC | 283 ms
124,400 KB |
testcase_10 | AC | 385 ms
144,256 KB |
testcase_11 | AC | 288 ms
127,280 KB |
testcase_12 | AC | 453 ms
158,352 KB |
testcase_13 | AC | 442 ms
158,292 KB |
testcase_14 | AC | 427 ms
158,088 KB |
testcase_15 | AC | 435 ms
158,392 KB |
testcase_16 | AC | 450 ms
158,220 KB |
testcase_17 | AC | 437 ms
161,200 KB |
testcase_18 | AC | 426 ms
158,160 KB |
testcase_19 | AC | 440 ms
158,208 KB |
testcase_20 | AC | 436 ms
158,292 KB |
testcase_21 | AC | 433 ms
158,088 KB |
testcase_22 | AC | 455 ms
151,300 KB |
testcase_23 | AC | 480 ms
151,496 KB |
testcase_24 | AC | 479 ms
151,500 KB |
testcase_25 | AC | 458 ms
151,428 KB |
testcase_26 | AC | 462 ms
151,520 KB |
testcase_27 | AC | 475 ms
151,672 KB |
testcase_28 | AC | 470 ms
151,616 KB |
testcase_29 | AC | 465 ms
151,944 KB |
testcase_30 | AC | 468 ms
151,820 KB |
testcase_31 | AC | 473 ms
151,528 KB |
testcase_32 | AC | 485 ms
152,076 KB |
testcase_33 | AC | 481 ms
151,812 KB |
testcase_34 | AC | 486 ms
151,052 KB |
testcase_35 | AC | 511 ms
152,964 KB |
testcase_36 | AC | 523 ms
151,184 KB |
testcase_37 | AC | 537 ms
162,444 KB |
testcase_38 | AC | 516 ms
160,004 KB |
testcase_39 | AC | 535 ms
162,320 KB |
testcase_40 | AC | 513 ms
159,760 KB |
testcase_41 | AC | 502 ms
162,596 KB |
testcase_42 | AC | 658 ms
162,448 KB |
testcase_43 | AC | 649 ms
162,952 KB |
testcase_44 | AC | 617 ms
159,704 KB |
testcase_45 | AC | 653 ms
160,552 KB |
testcase_46 | AC | 649 ms
161,428 KB |
testcase_47 | AC | 925 ms
166,968 KB |
testcase_48 | AC | 913 ms
166,788 KB |
testcase_49 | AC | 919 ms
167,048 KB |
testcase_50 | AC | 939 ms
166,792 KB |
testcase_51 | AC | 929 ms
166,796 KB |
testcase_52 | AC | 514 ms
159,668 KB |
testcase_53 | AC | 486 ms
157,764 KB |
testcase_54 | AC | 489 ms
154,880 KB |
testcase_55 | AC | 496 ms
159,364 KB |
testcase_56 | AC | 491 ms
159,360 KB |
testcase_57 | AC | 486 ms
150,196 KB |
testcase_58 | AC | 464 ms
150,284 KB |
testcase_59 | AC | 484 ms
152,928 KB |
testcase_60 | AC | 494 ms
158,112 KB |
testcase_61 | AC | 472 ms
155,180 KB |
testcase_62 | AC | 877 ms
175,588 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=float("inf") 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)