結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | ygd. |
提出日時 | 2021-06-15 23:15:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,400 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,420 KB |
実行使用メモリ | 146,816 KB |
最終ジャッジ日時 | 2024-06-08 15:45:53 |
合計ジャッジ時間 | 22,566 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
146,816 KB |
testcase_01 | AC | 43 ms
54,528 KB |
testcase_02 | AC | 44 ms
54,528 KB |
testcase_03 | AC | 43 ms
54,656 KB |
testcase_04 | AC | 148 ms
84,736 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 180 ms
88,448 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 167 ms
90,112 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 70 ms
66,304 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 158 ms
79,872 KB |
testcase_31 | WA | - |
testcase_32 | AC | 120 ms
77,312 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 127 ms
77,884 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 162 ms
79,236 KB |
testcase_41 | AC | 123 ms
77,184 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 69 ms
75,392 KB |
testcase_45 | AC | 44 ms
54,656 KB |
testcase_46 | AC | 190 ms
92,800 KB |
testcase_47 | AC | 204 ms
91,648 KB |
testcase_48 | WA | - |
testcase_49 | AC | 339 ms
95,360 KB |
testcase_50 | AC | 474 ms
100,428 KB |
testcase_51 | AC | 179 ms
107,648 KB |
testcase_52 | AC | 490 ms
101,972 KB |
testcase_53 | AC | 245 ms
92,672 KB |
testcase_54 | AC | 143 ms
98,808 KB |
testcase_55 | AC | 401 ms
98,304 KB |
testcase_56 | AC | 72 ms
75,520 KB |
testcase_57 | WA | - |
testcase_58 | AC | 263 ms
92,468 KB |
testcase_59 | AC | 157 ms
94,760 KB |
testcase_60 | AC | 97 ms
87,680 KB |
testcase_61 | AC | 211 ms
94,848 KB |
testcase_62 | AC | 331 ms
101,364 KB |
testcase_63 | AC | 251 ms
101,888 KB |
testcase_64 | TLE | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
ソースコード
from heapq import heapify, heappop, heappush from collections import deque 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)) Q = deque([]) Q.append(S) d_bfs = [INF]*N d_bfs[S] = 1 while Q: v = Q.popleft() for cost, u in G[v]: if d_bfs[u] != INF: continue d_bfs[u] = d_bfs[v] + 1 Q.append(v) if d_bfs[T] == INF: print("Impossible");exit() def dijkstra_heap2(s,G,t,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 = 20 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 v == t and n >= K: break 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,T,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()