結果

問題 No.1 道のショートカット
ユーザー ゆるく
提出日時 2014-10-25 05:43:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-07-08 03:33:07
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 34 WA * 6
権限があれば一括ダウンロードができます

ソースコード

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(dict)
for i in range(v):
    try:
        if ((d[s[i]][t[i]] >> 16) & 0xFFFFFFFF) > m[i]:
            d[s[i]][t[i]] = (m[i] << 16) + y[i]
    except:
        d[s[i]][t[i]] = (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]:
                nextcost = (d[hpos][dd] & 0xFFFF) + hcost
                nexthm = ((d[hpos][dd] >> 16) & 0xFFFFFFFF) + hm
                if nextcost <= c:
                    heapq.heappush(heap, (nexthm << 32) + (nextcost << 16) + dd)
    return -1
print(solve())
0