結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | ygd. |
提出日時 | 2021-06-15 23:00:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,037 bytes |
コンパイル時間 | 588 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 159,888 KB |
最終ジャッジ日時 | 2024-06-08 15:29:27 |
合計ジャッジ時間 | 41,045 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,608 KB |
testcase_01 | AC | 37 ms
53,120 KB |
testcase_02 | AC | 38 ms
52,992 KB |
testcase_03 | AC | 39 ms
54,400 KB |
testcase_04 | AC | 149 ms
94,060 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 185 ms
101,112 KB |
testcase_08 | AC | 896 ms
108,320 KB |
testcase_09 | AC | 546 ms
93,436 KB |
testcase_10 | AC | 187 ms
108,016 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 330 ms
85,948 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 325 ms
85,264 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 917 ms
108,540 KB |
testcase_24 | AC | 920 ms
88,572 KB |
testcase_25 | AC | 293 ms
79,344 KB |
testcase_26 | AC | 150 ms
78,572 KB |
testcase_27 | AC | 263 ms
79,528 KB |
testcase_28 | AC | 510 ms
82,944 KB |
testcase_29 | AC | 781 ms
88,300 KB |
testcase_30 | AC | 434 ms
81,140 KB |
testcase_31 | AC | 460 ms
82,516 KB |
testcase_32 | AC | 182 ms
78,144 KB |
testcase_33 | AC | 643 ms
84,696 KB |
testcase_34 | AC | 462 ms
82,504 KB |
testcase_35 | AC | 831 ms
86,928 KB |
testcase_36 | AC | 704 ms
84,308 KB |
testcase_37 | AC | 219 ms
78,208 KB |
testcase_38 | AC | 372 ms
80,120 KB |
testcase_39 | AC | 196 ms
78,156 KB |
testcase_40 | AC | 392 ms
80,496 KB |
testcase_41 | AC | 167 ms
78,100 KB |
testcase_42 | AC | 586 ms
86,852 KB |
testcase_43 | AC | 587 ms
85,524 KB |
testcase_44 | AC | 76 ms
80,768 KB |
testcase_45 | AC | 53 ms
73,216 KB |
testcase_46 | AC | 636 ms
92,448 KB |
testcase_47 | AC | 472 ms
92,664 KB |
testcase_48 | AC | 381 ms
99,196 KB |
testcase_49 | AC | 816 ms
97,268 KB |
testcase_50 | AC | 988 ms
104,480 KB |
testcase_51 | AC | 1,411 ms
108,684 KB |
testcase_52 | AC | 1,027 ms
106,140 KB |
testcase_53 | AC | 493 ms
93,748 KB |
testcase_54 | AC | 728 ms
101,560 KB |
testcase_55 | AC | 889 ms
101,252 KB |
testcase_56 | AC | 78 ms
80,384 KB |
testcase_57 | AC | 1,316 ms
109,164 KB |
testcase_58 | AC | 556 ms
94,452 KB |
testcase_59 | AC | 651 ms
95,712 KB |
testcase_60 | AC | 121 ms
87,296 KB |
testcase_61 | AC | 992 ms
96,288 KB |
testcase_62 | AC | 1,132 ms
103,024 KB |
testcase_63 | AC | 1,152 ms
102,992 KB |
testcase_64 | WA | - |
testcase_65 | AC | 411 ms
89,288 KB |
testcase_66 | WA | - |
ソースコード
from heapq import heapify, heappop, heappush from math import inf def main(): N,S,T,K = map(int,input().split()); INF = float("inf") S-=1;T-=1 #0-index X = list(map(int,input().split())) G = [[] for _ in range(N)] M = int(input()) for _ in range(M): A,B,Y = map(int,input().split()) A-=1;B-=1 G[A].append((Y,B)) def dijkstra_heap2(s,G,K): INF = float("inf") #S:start, V: node, E: Edge, G: Graph V = len(G) #dp[i][j]: i番目の歌を歌って今j曲目(i番目の歌を含む) if K <= 10: MAX = 10 elif K <= 130: MAX = 1000 else: MAX = pow(10,5) dp = [[INF]*MAX for _ in range(V)] #d = [INF for _ in range(V)] dp[s][1] = X[s] prev = [[-1]*MAX for _ in range(V)] PQ = [] heappush(PQ,(X[s],s,1)) #時間, 位置, 何曲目 while PQ: c,v,n = heappop(PQ) if dp[v][n] < c: continue dp[v][n] = c if n+1 >= MAX: #これ以上は配列外参照 continue for cost,u in G[v]: if dp[u][n+1] <= cost + X[u] + dp[v][n]: continue dp[u][n+1] = cost + X[u] + dp[v][n] prev[u][n+1] = v heappush(PQ,(dp[u][n+1], u, n+1)) return dp, prev d, keiro = dijkstra_heap2(S,G,K) #print(d) #print(keiro) ans = INF num = INF #何曲か for i in range(K,len(d[T])): if d[T][i] < ans: ans = d[T][i] num = i if ans == INF: print("Impossible") else: print("Possible") print(ans) print(num) ret = [T+1] #1-index #num -= 1 now = T while num > 1: pre = keiro[now][num] ret.append(pre+1) #1-index now = pre num -= 1 ret.reverse() print(*ret) if __name__ == '__main__': main()