結果
問題 | No.1014 competitive fighting |
ユーザー | vwxyz |
提出日時 | 2022-01-08 18:15:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 18,003 bytes |
コンパイル時間 | 843 ms |
コンパイル使用メモリ | 82,212 KB |
実行使用メモリ | 128,964 KB |
最終ジャッジ日時 | 2024-11-14 09:41:54 |
合計ジャッジ時間 | 41,720 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
57,876 KB |
testcase_01 | AC | 47 ms
57,352 KB |
testcase_02 | WA | - |
testcase_03 | AC | 47 ms
58,156 KB |
testcase_04 | AC | 46 ms
59,224 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 777 ms
118,352 KB |
testcase_11 | AC | 400 ms
123,156 KB |
testcase_12 | WA | - |
testcase_13 | AC | 1,168 ms
106,404 KB |
testcase_14 | AC | 1,133 ms
103,988 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 1,607 ms
128,964 KB |
testcase_20 | AC | 933 ms
97,104 KB |
testcase_21 | AC | 1,390 ms
115,288 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 133 ms
76,956 KB |
testcase_30 | AC | 1,600 ms
127,300 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 187 ms
80,628 KB |
testcase_34 | AC | 576 ms
115,388 KB |
testcase_35 | WA | - |
testcase_36 | AC | 528 ms
110,720 KB |
testcase_37 | AC | 162 ms
78,668 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 469 ms
106,500 KB |
testcase_41 | AC | 382 ms
96,944 KB |
testcase_42 | AC | 678 ms
126,020 KB |
testcase_43 | AC | 180 ms
79,584 KB |
testcase_44 | AC | 631 ms
121,412 KB |
testcase_45 | WA | - |
testcase_46 | AC | 201 ms
80,824 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | AC | 163 ms
79,228 KB |
testcase_50 | AC | 661 ms
123,076 KB |
testcase_51 | AC | 454 ms
102,220 KB |
testcase_52 | AC | 167 ms
78,788 KB |
testcase_53 | WA | - |
ソースコード
import bisect from collections import deque import sys readline=sys.stdin.readline class Segment_Tree: def __init__(self,N,f,e,lst=None): self.f=f self.e=e self.N=N if lst==None: self.segment_tree=[self.e]*2*self.N else: assert len(lst)<=self.N self.segment_tree=[self.e]*self.N+[x for x in lst]+[self.e]*(N-len(lst)) for i in range(self.N-1,0,-1): self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1]) def __getitem__(self,i): if type(i)==int: if -self.N<=i<0: return self.segment_tree[i+self.N*2] elif 0<=i<self.N: return self.segment_tree[i+self.N] else: raise IndexError('list index out of range') else: a,b,c=i.start,i.stop,i.step if a==None or a<-self.N: a=self.N elif self.N<=a: a=self.N*2 elif a<0: a+=self.N*2 else: a+=self.N if b==None or self.N<=b: b=self.N*2 elif b<-self.N: b=self.N elif b<0: b+=self.N*2 else: b+=self.N return self.segment_tree[slice(a,b,c)] def __setitem__(self,i,x): if -self.N<=i<0: i+=self.N*2 elif 0<=i<self.N: i+=self.N else: raise IndexError('list index out of range') self.segment_tree[i]=x while i>1: i>>= 1 self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1]) def Build(self,lst): for i,x in enumerate(lst,self.N): self.segment_tree[i]=x for i in range(self.N-1,0,-1): self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1]) def Fold(self,L=None,R=None): if L==None or L<-self.N: L=self.N elif self.N<=L: L=self.N*2 elif L<0: L+=self.N*2 else: L+=self.N if R==None or self.N<=R: R=self.N*2 elif R<-self.N: R=self.N elif R<0: R+=self.N*2 else: R+=self.N vL=self.e vR=self.e while L<R: if L&1: vL=self.f(vL,self.segment_tree[L]) L+=1 if R&1: R-=1 vR=self.f(self.segment_tree[R],vR) L>>=1 R>>=1 return self.f(vL,vR) def Fold_Index(self,L=None,R=None): if L==None or L<-self.N: L=self.N elif self.N<=L: L=self.N*2 elif L<0: L+=self.N*2 else: L+=self.N if R==None or self.N<=R: R=self.N*2 elif R<-self.N: R=self.N elif R<0: R+=self.N*2 else: R+=self.N if L==R: return None x=self.Fold(L-self.N,R-self.N) while L<R: if L&1: if self.segment_tree[L]==x: i=L break L+=1 if R&1: R-=1 if self.segment_tree[R]==x: i=R break L>>=1 R>>=1 while i<self.N: if self.segment_tree[i]==self.segment_tree[i<<1]: i<<=1 else: i<<=1 i|=1 i-=self.N return i def Interval_Decomp(self,L=None,R=None): if L==None or L<-self.N: L=self.N elif self.N<=L: L=self.N*2 elif L<0: L+=self.N*2 else: L+=self.N if R==None or self.N<=R: R=self.N*2 elif R<-self.N: R=self.N elif R<0: R+=self.N*2 else: R+=self.N interval_decomp=[] while L<R: if R&1: R-=1 interval_decomp.append(R) if L&1: interval_decomp.append(L) L+=1 L>>=1 R>>=1 interval_decomp.sort() return interval_decomp def __str__(self): return '['+', '.join(map(str,self.segment_tree[self.N:]))+']' class Graph: def __init__(self,V,edges=False,graph=False,directed=False,weighted=False,inf=float("inf")): self.V=V self.directed=directed self.weighted=weighted self.inf=inf if not graph: self.edges=edges self.graph=[[] for i in range(self.V)] if weighted: for i,j,d in self.edges: self.graph[i].append((j,d)) if not self.directed: self.graph[j].append((i,d)) else: for i,j in self.edges: self.graph[i].append(j) if not self.directed: self.graph[j].append(i) else: self.graph=graph self.edges=[] for i in range(self.V): if self.weighted: for j,d in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j,d)) else: for j in self.graph[i]: if self.directed or not self.directed and i<=j: self.edges.append((i,j)) def MIV_DFS(self,initial_vertices=None,bipartite_graph=False,cycle_detection=False,directed_acyclic=False,euler_tour=False,linked_components=False,lowlink=False,parents=False,postorder=False,preorder=False,subtree_size=False,topological_sort=False,unweighted_dist=False,weighted_dist=False): if initial_vertices==None: initial_vertices=[s for s in range(self.V)] seen=[False]*self.V finished=[False]*self.V if bipartite_graph: bg=[None]*self.V cnt=-1 if directed_acyclic or cycle_detection or topological_sort: dag=True if euler_tour: et=[] if linked_components: lc=[] if lowlink: order=[None]*self.V ll=[None]*self.V idx=0 if parents or cycle_detection or lowlink or subtree_size: ps=[None]*self.V if postorder or topological_sort: post=[] if preorder: pre=[] if subtree_size: ss=[1]*self.V if unweighted_dist: uwd=[self.inf]*self.V if weighted_dist: wd=[self.inf]*self.V for s in initial_vertices: if seen[s]: continue if bipartite_graph: cnt+=1 bg[s]=(cnt,0) if linked_components: lc.append([]) if unweighted_dist: uwd[s]=0 if weighted_dist: wd[s]=0 stack=[(s,0)] if self.weighted else [s] while stack: if self.weighted: x,d=stack.pop() else: x=stack.pop() if not seen[x]: seen[x]=True stack.append((x,d) if self.weighted else x) if euler_tour: et.append(x) if linked_components: lc[-1].append(x) if lowlink: order[x]=idx ll[x]=idx idx+=1 if preorder: pre.append(x) for y in self.graph[x]: if self.weighted: y,d=y if not seen[y]: stack.append((y,d) if self.weighted else y) if bipartite_graph: bg[y]=(cnt,bg[x][1]^1) if parents or cycle_detection or lowlink or subtree_size: ps[y]=x if unweighted_dist or bipartite_graph: uwd[y]=uwd[x]+1 if weighted_dist: wd[y]=wd[x]+d elif not finished[y]: if directed_acyclic and dag: dag=False if cycle_detection: cd=(y,x) elif not finished[x]: finished[x]=True if euler_tour: et.append(~x) if lowlink: for y in self.graph[x]: if self.weighted: y,d=y if ps[x]==y: continue ll[x]=min(ll[x],order[y]) if x!=s: ll[ps[x]]=min(ll[ps[x]],ll[x]) if postorder or topological_sort: post.append(x) if subtree_size: for y in self.graph[x]: if self.weighted: y,d=y if y==ps[x]: continue ss[x]+=ss[y] if bipartite_graph: bg_=bg bg=[[[],[]] for i in range(cnt+1)] for tpl in self.edges: i,j=tpl[:2] if self.weighted else tpl if not bg_[i][1]^bg_[j][1]: bg[bg_[i][0]]=False for x in range(self.V): if bg[bg_[x][0]]: bg[bg_[x][0]][bg_[x][1]].append(x) retu=() if bipartite_graph: retu+=(bg,) if cycle_detection: if dag: cd=[] else: y,x=cd cd=self.Route_Restoration(y,x,ps) retu+=(cd,) if directed_acyclic: retu+=(dag,) if euler_tour: retu+=(et,) if linked_components: retu+=(lc,) if lowlink: retu=(ll,) if parents: retu+=(ps,) if postorder: retu+=(post,) if preorder: retu+=(pre,) if subtree_size: retu+=(ss,) if topological_sort: if dag: tp_sort=post[::-1] else: tp_sort=[] retu+=(tp_sort,) if unweighted_dist: retu+=(uwd,) if weighted_dist: retu+=(wd,) if len(retu)==1: retu=retu[0] return retu def SIV_DFS(self,s,bipartite_graph=False,cycle_detection=False,directed_acyclic=False,euler_tour=False,linked_components=False,lowlink=False,parents=False,postorder=False,preorder=False,subtree_size=False,topological_sort=False,unweighted_dist=False,weighted_dist=False): seen=[False]*self.V finished=[False]*self.V if directed_acyclic or cycle_detection or topological_sort: dag=True if euler_tour: et=[] if linked_components: lc=[] if lowlink: order=[None]*self.V ll=[None]*self.V idx=0 if parents or cycle_detection or lowlink or subtree_size: ps=[None]*self.V if postorder or topological_sort: post=[] if preorder: pre=[] if subtree_size: ss=[1]*self.V if unweighted_dist or bipartite_graph: uwd=[self.inf]*self.V uwd[s]=0 if weighted_dist: wd=[self.inf]*self.V wd[s]=0 stack=[(s,0)] if self.weighted else [s] while stack: if self.weighted: x,d=stack.pop() else: x=stack.pop() if not seen[x]: seen[x]=True stack.append((x,d) if self.weighted else x) if euler_tour: et.append(x) if linked_components: lc.append(x) if lowlink: order[x]=idx ll[x]=idx idx+=1 if preorder: pre.append(x) for y in self.graph[x]: if self.weighted: y,d=y if not seen[y]: stack.append((y,d) if self.weighted else y) if parents or cycle_detection or lowlink or subtree_size: ps[y]=x if unweighted_dist or bipartite_graph: uwd[y]=uwd[x]+1 if weighted_dist: wd[y]=wd[x]+d elif not finished[y]: if (directed_acyclic or cycle_detection or topological_sort) and dag: dag=False if cycle_detection: cd=(y,x) elif not finished[x]: finished[x]=True if euler_tour: et.append(~x) if lowlink: for y in self.graph[x]: if self.weighted: y,d=y if ps[x]==y: continue ll[x]=min(ll[x],order[y]) if x!=s: ll[ps[x]]=min(ll[ps[x]],ll[x]) if postorder or topological_sort: post.append(x) if subtree_size: for y in self.graph[x]: if self.weighted: y,d=y if y==ps[x]: continue ss[x]+=ss[y] if bipartite_graph: bg=[[],[]] for tpl in self.edges: x,y=tpl[:2] if self.weighted else tpl if uwd[x]==self.inf or uwd[y]==self.inf: continue if not uwd[x]%2^uwd[y]%2: bg=False break else: for x in range(self.V): if uwd[x]==self.inf: continue bg[uwd[x]%2].append(x) retu=() if bipartite_graph: retu+=(bg,) if cycle_detection: if dag: cd=[] else: y,x=cd cd=self.Route_Restoration(y,x,ps) retu+=(cd,) if directed_acyclic: retu+=(dag,) if euler_tour: retu+=(et,) if linked_components: retu+=(lc,) if lowlink: retu=(ll,) if parents: retu+=(ps,) if postorder: retu+=(post,) if preorder: retu+=(pre,) if subtree_size: retu+=(ss,) if topological_sort: if dag: tp_sort=post[::-1] else: tp_sort=[] retu+=(tp_sort,) if unweighted_dist: retu+=(uwd,) if weighted_dist: retu+=(wd,) if len(retu)==1: retu=retu[0] return retu def SCC(self): reverse_graph=[[] for i in range(self.V)] for tpl in self.edges: u,v=tpl[:2] if self.weighted else tpl reverse_graph[v].append(u) postorder=self.MIV_DFS(postorder=True) scc_points=[] seen=[False]*self.V for s in postorder[::-1]: if seen[s]: continue queue=deque([s]) seen[s]=True lst=[] while queue: x=queue.popleft() lst.append(x) for y in reverse_graph[x]: if not seen[y]: seen[y]=True queue.append(y) scc_points.append(lst) l=len(scc_points) idx=[None]*self.V for i in range(l): for x in scc_points[i]: idx[x]=i scc_edges=set() for tpl in self.edges: u,v=tpl[:2] if self.weighted else tpl if idx[u]!=idx[v]: scc_edges.add((idx[u],idx[v])) scc_edges=list(scc_edges) return scc_points,scc_edges N=int(readline()) ABCI=[] for i in range(N): a,b,c=map(int,readline().split()) ABCI.append((a,b,c,i)) ABCI.sort(key=lambda tpl:(tpl[0],tpl[2]-tpl[1])) edges=[] A,B,C,I=[],[],[],[] for a,b,c,i in ABCI: A.append(a) B.append(b) C.append(c) I.append(i) inf=float("inf") dp=[0]*N dp=Segment_Tree(N,max,0,dp) for i in range(N): r=bisect.bisect_right(A,B[i]-C[i]) dp[i]=max(dp[i],dp.Fold(min(r,i+1),r)+B[i]) dp[i]=max(dp[i],dp.Fold(0,min(r,i))+B[i]) dp_=[x for x in dp] dp_=Segment_Tree(N,max,0,dp_) for i in range(N): r=bisect.bisect_right(A,B[i]-C[i]) dp_[i]=max(dp_[i],dp_.Fold(min(r,i+1),r)+B[i]) dp_[i]=max(dp_[i],dp_.Fold(0,min(r,i))+B[i]) dp=[0 if dp[i]==dp_[i] else inf] dp=Segment_Tree(N,max,0,dp) for i in range(N): r=bisect.bisect_right(A,B[i]-C[i]) dp[i]=max(dp[i],dp.Fold(min(r,i+1),r)+B[i]) dp[i]=max(dp[i],dp.Fold(0,min(r,i))+B[i]) ans_lst=[None]*N for i in range(N): ans_lst[I[i]]=dp[i] for i in range(N): if ans_lst[i]==float("inf"): ans_lst[i]="BAN" print(*ans_lst,sep="\n")