結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | ygd. |
提出日時 | 2021-06-15 23:33:50 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,440 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 188,636 KB |
最終ジャッジ日時 | 2024-06-08 16:12:29 |
合計ジャッジ時間 | 25,730 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
54,400 KB |
testcase_01 | AC | 48 ms
54,144 KB |
testcase_02 | AC | 44 ms
54,528 KB |
testcase_03 | AC | 45 ms
54,528 KB |
testcase_04 | AC | 147 ms
84,608 KB |
testcase_05 | AC | 469 ms
123,960 KB |
testcase_06 | RE | - |
testcase_07 | AC | 196 ms
88,320 KB |
testcase_08 | AC | 726 ms
114,720 KB |
testcase_09 | AC | 563 ms
97,700 KB |
testcase_10 | AC | 170 ms
89,856 KB |
testcase_11 | AC | 278 ms
103,680 KB |
testcase_12 | AC | 399 ms
118,128 KB |
testcase_13 | AC | 191 ms
95,744 KB |
testcase_14 | AC | 181 ms
95,616 KB |
testcase_15 | AC | 122 ms
80,768 KB |
testcase_16 | AC | 219 ms
103,996 KB |
testcase_17 | AC | 546 ms
92,140 KB |
testcase_18 | AC | 396 ms
127,920 KB |
testcase_19 | AC | 329 ms
104,960 KB |
testcase_20 | AC | 322 ms
86,648 KB |
testcase_21 | AC | 273 ms
127,812 KB |
testcase_22 | AC | 271 ms
125,548 KB |
testcase_23 | AC | 383 ms
98,816 KB |
testcase_24 | AC | 172 ms
80,288 KB |
testcase_25 | AC | 165 ms
78,848 KB |
testcase_26 | AC | 67 ms
66,048 KB |
testcase_27 | AC | 147 ms
78,720 KB |
testcase_28 | AC | 167 ms
79,744 KB |
testcase_29 | AC | 188 ms
80,804 KB |
testcase_30 | AC | 168 ms
79,872 KB |
testcase_31 | AC | 182 ms
81,100 KB |
testcase_32 | AC | 132 ms
77,056 KB |
testcase_33 | AC | 208 ms
81,436 KB |
testcase_34 | AC | 204 ms
79,792 KB |
testcase_35 | AC | 251 ms
81,332 KB |
testcase_36 | AC | 237 ms
80,460 KB |
testcase_37 | AC | 133 ms
77,440 KB |
testcase_38 | AC | 198 ms
79,072 KB |
testcase_39 | AC | 140 ms
77,824 KB |
testcase_40 | AC | 174 ms
79,104 KB |
testcase_41 | AC | 127 ms
77,312 KB |
testcase_42 | AC | 194 ms
80,756 KB |
testcase_43 | AC | 193 ms
81,148 KB |
testcase_44 | AC | 79 ms
75,008 KB |
testcase_45 | AC | 47 ms
54,400 KB |
testcase_46 | AC | 200 ms
92,544 KB |
testcase_47 | AC | 201 ms
91,520 KB |
testcase_48 | AC | 254 ms
96,384 KB |
testcase_49 | AC | 342 ms
95,104 KB |
testcase_50 | AC | 475 ms
99,968 KB |
testcase_51 | AC | 192 ms
107,264 KB |
testcase_52 | AC | 483 ms
101,504 KB |
testcase_53 | AC | 245 ms
92,416 KB |
testcase_54 | AC | 157 ms
98,944 KB |
testcase_55 | AC | 403 ms
97,664 KB |
testcase_56 | AC | 80 ms
75,648 KB |
testcase_57 | AC | 380 ms
108,032 KB |
testcase_58 | AC | 270 ms
92,416 KB |
testcase_59 | AC | 176 ms
94,464 KB |
testcase_60 | AC | 111 ms
87,552 KB |
testcase_61 | AC | 209 ms
94,592 KB |
testcase_62 | AC | 330 ms
100,864 KB |
testcase_63 | AC | 254 ms
101,760 KB |
testcase_64 | RE | - |
testcase_65 | RE | - |
testcase_66 | RE | - |
ソースコード
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(u) 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]: nxt = min(n+1, MAX-1) if dp[u][nxt] <= cost + X[u] + dp[v][n]: continue dp[u][nxt] = cost + X[u] + dp[v][n] prev[u][nxt] = v heappush(PQ,(dp[u][n+1], u, nxt)) 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()