結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | 👑 Kazun |
提出日時 | 2021-05-20 00:32:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,102 ms / 3,000 ms |
コード長 | 2,570 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 198,996 KB |
最終ジャッジ日時 | 2024-05-08 16:22:09 |
合計ジャッジ時間 | 24,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,992 KB |
testcase_01 | AC | 41 ms
53,120 KB |
testcase_02 | AC | 40 ms
52,992 KB |
testcase_03 | AC | 45 ms
52,992 KB |
testcase_04 | AC | 182 ms
107,744 KB |
testcase_05 | AC | 492 ms
149,508 KB |
testcase_06 | AC | 315 ms
109,768 KB |
testcase_07 | AC | 380 ms
118,292 KB |
testcase_08 | AC | 711 ms
141,400 KB |
testcase_09 | AC | 354 ms
118,868 KB |
testcase_10 | AC | 238 ms
116,884 KB |
testcase_11 | AC | 333 ms
120,124 KB |
testcase_12 | AC | 357 ms
146,332 KB |
testcase_13 | AC | 166 ms
101,248 KB |
testcase_14 | AC | 171 ms
106,368 KB |
testcase_15 | AC | 109 ms
86,784 KB |
testcase_16 | AC | 210 ms
115,736 KB |
testcase_17 | AC | 248 ms
107,520 KB |
testcase_18 | AC | 380 ms
166,768 KB |
testcase_19 | AC | 297 ms
117,088 KB |
testcase_20 | AC | 352 ms
99,840 KB |
testcase_21 | AC | 258 ms
127,764 KB |
testcase_22 | AC | 270 ms
132,520 KB |
testcase_23 | AC | 409 ms
140,452 KB |
testcase_24 | AC | 151 ms
78,548 KB |
testcase_25 | AC | 175 ms
78,856 KB |
testcase_26 | AC | 79 ms
71,808 KB |
testcase_27 | AC | 142 ms
78,068 KB |
testcase_28 | AC | 174 ms
78,992 KB |
testcase_29 | AC | 179 ms
79,592 KB |
testcase_30 | AC | 168 ms
78,592 KB |
testcase_31 | AC | 160 ms
78,336 KB |
testcase_32 | AC | 140 ms
77,872 KB |
testcase_33 | AC | 198 ms
78,976 KB |
testcase_34 | AC | 183 ms
79,576 KB |
testcase_35 | AC | 221 ms
79,560 KB |
testcase_36 | AC | 223 ms
79,596 KB |
testcase_37 | AC | 130 ms
77,696 KB |
testcase_38 | AC | 171 ms
78,540 KB |
testcase_39 | AC | 144 ms
77,952 KB |
testcase_40 | AC | 173 ms
78,160 KB |
testcase_41 | AC | 125 ms
77,624 KB |
testcase_42 | AC | 199 ms
79,836 KB |
testcase_43 | AC | 208 ms
79,444 KB |
testcase_44 | AC | 85 ms
77,440 KB |
testcase_45 | AC | 47 ms
59,776 KB |
testcase_46 | AC | 174 ms
79,180 KB |
testcase_47 | AC | 181 ms
81,368 KB |
testcase_48 | AC | 252 ms
88,868 KB |
testcase_49 | AC | 238 ms
85,156 KB |
testcase_50 | AC | 333 ms
92,928 KB |
testcase_51 | AC | 149 ms
78,276 KB |
testcase_52 | AC | 329 ms
92,520 KB |
testcase_53 | AC | 206 ms
85,496 KB |
testcase_54 | AC | 120 ms
77,980 KB |
testcase_55 | AC | 294 ms
90,164 KB |
testcase_56 | AC | 84 ms
77,952 KB |
testcase_57 | AC | 273 ms
86,360 KB |
testcase_58 | AC | 243 ms
85,564 KB |
testcase_59 | AC | 146 ms
78,364 KB |
testcase_60 | AC | 98 ms
77,824 KB |
testcase_61 | AC | 200 ms
80,188 KB |
testcase_62 | AC | 257 ms
83,980 KB |
testcase_63 | AC | 235 ms
81,240 KB |
testcase_64 | AC | 1,102 ms
198,996 KB |
testcase_65 | AC | 157 ms
79,308 KB |
testcase_66 | AC | 317 ms
155,572 KB |
ソースコード
class Heap_Point: def __init__(self,x,d): self.d=d self.x=x def __str__(self): return "(point:{}, dist:{})".format(self.x,self.d) def __repr__(self): return str(self) def __lt__(self,other): return self.d<other.d def __iter__(self): yield from (self.x,self.d) #================================================ import sys from heapq import heapify,heappop,heappush input=sys.stdin.readline N,S,T,K=map(int,input().split()) X=["*"]+list(map(int,input().split())) M=int(input()) E=[[] for _ in range(N+1)] A=[]; B=[]; Y=[] for _ in range(M): a,b,y=map(int,input().split()) E[a].append((b,y)) A.append(a) B.append(b) Y.append(y) #================================================== #Validator assert 1<=N<=10**5,"Nが制約違反 (N={})".format(N) assert 1<=S<=N,"Sが制約違反 (S={}, N={})".format(S,N) assert 1<=T<=N,"Tが制約違反 (T={}, N={})".format(T,N) assert 1<=K<=3*10**4,"Kが制約違反 (K={})".format(K) assert 1<=M<=min(N*N,2*10**5),"M が制約違反 (M={}, N^2={})".format(M,N*N) for i in range(M): assert 1<=A[i]<=N, "A_{}が制約違反 (A_{}={})".format(i+1,i+1,A[i]) assert 1<=B[i]<=N, "B_{}が制約違反 (B_{}={})".format(i+1,i+1,B[i]) assert len(set([(a,b) for a,b in zip(A,B)]))==M,"(A,B) に重複あり" for i in range(M): assert 1<=Y[i]<=10**9,"Y_{}が制約違反 (Y_{}={})".format(i+1,i+1,Y[i]) Type_A=(1<=N<=10**5) and (1<=K<=10) Type_B=(1<=N<=130) and (1<=K<=130) Type_C=(1<=N<=10) and (1<=K<=3*10**4) print("[A]: {}".format(Type_A),file=sys.stderr) print("[B]: {}".format(Type_B),file=sys.stderr) print("[C]: {}".format(Type_C),file=sys.stderr) assert Type_A or Type_B or Type_C,"[A],[B],[C] のいずれも満たさない (N={}, K={})".format(N,K) #================================================== inf=float("inf") DP=[[inf]*(K+1) for _ in range(N+1)] DP[S][1]=X[S] Reverse=[[(0,0) for _ in range(K+1)] for _ in range(N+1)] Q=[Heap_Point((S,1),0)] heapify(Q) while Q: (x,k),d=heappop(Q) if DP[x][k]<d: continue if x==T and k==K: break l=min(k+1,K) for y,m in E[x]: if DP[x][k]+m+X[y]<DP[y][l]: DP[y][l]=DP[x][k]+m+X[y] Reverse[y][l]=(x,k) heappush(Q,Heap_Point((y,l),DP[y][l])) V=DP[T][K] if V<inf: x,k=T,K P=[] while k>0: P.append(x) x,k=Reverse[x][k] print("Possible") print(V) print(len(P)) print(*P[::-1]) else: print("Impossible")