結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-16 23:34:53 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,135 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-07-08 05:13:37 |
| 合計ジャッジ時間 | 2,424 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 RE * 26 |
ソースコード
from heapq import heappop, heappush
def main():
""" main """
N = int(input())
C = int(input())
V = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
Y = list(map(int, input().split()))
M = list(map(int, input().split()))
ways_from = {}
for i in range(V):
if ways_from.get(S[i]):
ways_from[S[i]].append({'next': T[i], 'cost': Y[i], 'min': M[i]})
else:
ways_from[S[i]] = [{'next': T[i], 'cost': Y[i], 'min': M[i]}]
candidates = [(0, {'pos': 1, 'cost': 0})]
res = None
while candidates:
candidate = heappop(candidates)
if candidate[1]['pos'] == N:
res = candidate[0]
break
if not ways_from[candidate[1]['pos']]:
continue
for way in ways_from[candidate[1]['pos']]:
next_cost = candidate[1]['cost'] + way['cost']
if C < next_cost:
continue
heappush(
candidates, (candidate[0] + way['min'], {'pos': way['next'], 'cost': next_cost}))
return res or -1
print(main())