結果
問題 | No.1898 Battle and Exchange |
ユーザー | persimmon-persimmon |
提出日時 | 2022-04-14 16:09:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,452 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 86,868 KB |
実行使用メモリ | 193,904 KB |
最終ジャッジ日時 | 2023-08-25 21:22:03 |
合計ジャッジ時間 | 32,840 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,360 KB |
testcase_01 | AC | 78 ms
71,332 KB |
testcase_02 | AC | 79 ms
71,324 KB |
testcase_03 | AC | 78 ms
71,252 KB |
testcase_04 | AC | 101 ms
76,604 KB |
testcase_05 | AC | 99 ms
76,012 KB |
testcase_06 | AC | 149 ms
78,388 KB |
testcase_07 | AC | 140 ms
78,464 KB |
testcase_08 | AC | 122 ms
77,576 KB |
testcase_09 | AC | 232 ms
81,868 KB |
testcase_10 | AC | 77 ms
71,260 KB |
testcase_11 | AC | 113 ms
77,944 KB |
testcase_12 | AC | 168 ms
78,916 KB |
testcase_13 | AC | 77 ms
71,232 KB |
testcase_14 | AC | 158 ms
78,984 KB |
testcase_15 | AC | 78 ms
71,504 KB |
testcase_16 | AC | 152 ms
78,720 KB |
testcase_17 | AC | 305 ms
80,932 KB |
testcase_18 | AC | 779 ms
92,956 KB |
testcase_19 | AC | 1,429 ms
111,448 KB |
testcase_20 | AC | 759 ms
96,712 KB |
testcase_21 | AC | 3,550 ms
187,560 KB |
testcase_22 | AC | 118 ms
77,420 KB |
testcase_23 | AC | 131 ms
78,032 KB |
testcase_24 | AC | 139 ms
78,124 KB |
testcase_25 | AC | 160 ms
78,612 KB |
testcase_26 | AC | 84 ms
75,260 KB |
testcase_27 | AC | 193 ms
80,300 KB |
testcase_28 | AC | 204 ms
80,384 KB |
testcase_29 | AC | 255 ms
83,500 KB |
testcase_30 | AC | 179 ms
78,800 KB |
testcase_31 | AC | 116 ms
77,376 KB |
testcase_32 | AC | 498 ms
121,636 KB |
testcase_33 | AC | 1,062 ms
193,904 KB |
testcase_34 | AC | 499 ms
111,400 KB |
testcase_35 | AC | 599 ms
137,528 KB |
testcase_36 | AC | 402 ms
111,444 KB |
testcase_37 | AC | 768 ms
103,124 KB |
testcase_38 | TLE | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
ソースコード
from heapq import heappop,heappush def solv1(n,m,uv,abc): # 1つの辺を通ることを考える。その辺を行き来することで2頂点のカードの計6枚のうち上位3枚を手に入れられる。 # ->通ったことのある頂点の上位3枚のカードを手札にしていると考えてよい。 # ただし頂点1だけ別 g=[[] for _ in range(n)] for u,v in uv: u,v=u-1,v-1 g[u].append(v) g[v].append(u) # 頂点1に隣接する頂点の内、最弱の頂点 nv,nvalue=-1,float('inf') for v in g[0]: value=abc[v][0] if value<nvalue: nvalue=value nv=v # nv:1隣接頂点の内最弱頂点 def select_card(x,y): i,j=0,0 ret=[0]*4 for k in range(3): if x[-1-i]<y[-1-j]: ret[-1-k]=y[-1-j] ret[0]+=y[-1-j] j+=1 else: ret[-1-k]=x[-1-i] ret[0]+=x[-1-i] i+=1 return ret # xは少なくとも0とnvに勝てる値ではじめる r=max([x[0] for x in abc])+1 l=nvalue+1-max(abc[0][1:])+1 l=max(l,abc[0][0]+1) def search(x,nv): # 初めの札の合計がxで頂点nに到達可能か # 頂点1と頂点nvは攻略済み card=[x,1,1,x-2] card=select_card(card,abc[0]) card=select_card(card,abc[nv]) q=[] for v in g[0]: if v!=nv:heappush(q,[abc[v][0],v]) for v in g[nv]: if v!=0:heappush(q,[abc[v][0],v]) mi=set([0,nv]) while q: s,v=heappop(q) if not s<card[0]:# 頂点vに勝てない break if v==n-1: return True card=select_card(card,abc[v]) for v_ in g[v]: if v_ not in mi: mi.add(v_) heappush(q,[abc[v_][0],v_]) return n-1 in mi while r-l>1: x=(r+l)//2 ret=search(x,nv) if ret:l,r=l,x else:l,r=x,r for i in range(l,r+3): if search(i,nv):return i return -1 if __name__=='__main__': n,m=map(int,input().split()) uv=[list(map(int,input().split())) for _ in range(m)] abc=[] for _ in range(n): a,b,c=sorted(list(map(int,input().split()))) abc.append([a+b+c,a,b,c]) ret=solv1(n,m,uv,abc) print(ret-2,1,1)