結果

問題 No.1 道のショートカット
ユーザー ゆるくゆるく
提出日時 2014-11-05 23:37:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,083 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 9,628 KB
最終ジャッジ日時 2023-09-27 21:35:23
合計ジャッジ時間 2,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
9,396 KB
testcase_01 AC 23 ms
9,300 KB
testcase_02 AC 25 ms
9,304 KB
testcase_03 AC 25 ms
9,240 KB
testcase_04 AC 24 ms
9,220 KB
testcase_05 AC 25 ms
9,280 KB
testcase_06 AC 24 ms
9,264 KB
testcase_07 AC 23 ms
9,308 KB
testcase_08 AC 26 ms
9,592 KB
testcase_09 AC 27 ms
9,380 KB
testcase_10 AC 24 ms
9,484 KB
testcase_11 AC 25 ms
9,380 KB
testcase_12 AC 26 ms
9,560 KB
testcase_13 AC 27 ms
9,628 KB
testcase_14 AC 25 ms
9,236 KB
testcase_15 AC 24 ms
9,372 KB
testcase_16 AC 24 ms
9,408 KB
testcase_17 AC 23 ms
9,368 KB
testcase_18 AC 22 ms
9,324 KB
testcase_19 AC 23 ms
9,380 KB
testcase_20 AC 23 ms
9,320 KB
testcase_21 AC 24 ms
9,352 KB
testcase_22 AC 23 ms
9,252 KB
testcase_23 AC 25 ms
9,616 KB
testcase_24 AC 24 ms
9,364 KB
testcase_25 AC 24 ms
9,380 KB
testcase_26 AC 25 ms
9,292 KB
testcase_27 AC 26 ms
9,564 KB
testcase_28 AC 24 ms
9,308 KB
testcase_29 AC 25 ms
9,404 KB
testcase_30 AC 23 ms
9,244 KB
testcase_31 AC 23 ms
9,400 KB
testcase_32 AC 25 ms
9,488 KB
testcase_33 AC 24 ms
9,388 KB
testcase_34 AC 25 ms
9,504 KB
testcase_35 AC 25 ms
9,440 KB
testcase_36 AC 26 ms
9,396 KB
testcase_37 AC 25 ms
9,524 KB
testcase_38 AC 24 ms
9,284 KB
testcase_39 AC 23 ms
9,304 KB
testcase_40 AC 24 ms
9,416 KB
testcase_41 AC 23 ms
9,232 KB
testcase_42 AC 23 ms
9,224 KB
testcase_43 AC 24 ms
9,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
from collections import defaultdict, deque
n = int(input())
c = int(input())
v = int(input())
s = tuple(map(int, input().split()))
t = tuple(map(int, input().split()))
y = tuple(map(int, input().split()))
m = tuple(map(int, input().split()))

d = defaultdict(lambda : defaultdict(list))
for i in range(v):
    d[s[i]][t[i]].append((m[i] << 16) + y[i])

def solve():
    heap = []
    heapq.heappush(heap, (0 << 32) + (0 << 16) + 1)
    while (heap):
        h = heapq.heappop(heap)
        hm = (h >> 32) & 0xFFFFFFFF
        hcost = (h >> 16) & 0xFFFF
        hpos = h & 0xFFFF
        if hpos == n:
            return hm
        else:
            for dd in d[hpos]:
                for td in d[hpos][dd]:
                    nextcost = (td & 0xFFFF) + hcost
                    nexthm = ((td >> 16) & 0xFFFFFFFF) + hm
                    if nextcost <= c:
                        heapq.heappush(heap, (nexthm << 32) + (nextcost << 16) + dd)
    return -1
print(solve())
0