結果

問題 No.1 道のショートカット
ユーザー takakintakakin
提出日時 2020-04-11 22:38:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 19,572 KB
最終ジャッジ日時 2023-09-27 22:27:12
合計ジャッジ時間 3,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,464 KB
testcase_01 AC 14 ms
8,492 KB
testcase_02 AC 13 ms
8,548 KB
testcase_03 AC 13 ms
8,452 KB
testcase_04 AC 14 ms
8,320 KB
testcase_05 AC 13 ms
8,452 KB
testcase_06 AC 14 ms
8,412 KB
testcase_07 AC 13 ms
8,332 KB
testcase_08 AC 95 ms
16,964 KB
testcase_09 AC 55 ms
13,040 KB
testcase_10 AC 41 ms
10,648 KB
testcase_11 AC 65 ms
12,968 KB
testcase_12 AC 142 ms
19,572 KB
testcase_13 AC 134 ms
19,316 KB
testcase_14 AC 22 ms
9,304 KB
testcase_15 AC 17 ms
8,936 KB
testcase_16 AC 29 ms
10,464 KB
testcase_17 AC 16 ms
8,960 KB
testcase_18 AC 21 ms
9,444 KB
testcase_19 AC 28 ms
10,412 KB
testcase_20 AC 32 ms
10,112 KB
testcase_21 AC 35 ms
10,916 KB
testcase_22 AC 25 ms
9,780 KB
testcase_23 AC 135 ms
17,052 KB
testcase_24 AC 150 ms
18,804 KB
testcase_25 AC 52 ms
11,916 KB
testcase_26 AC 37 ms
10,984 KB
testcase_27 AC 110 ms
16,680 KB
testcase_28 AC 17 ms
8,768 KB
testcase_29 AC 30 ms
9,648 KB
testcase_30 AC 17 ms
8,548 KB
testcase_31 AC 24 ms
9,392 KB
testcase_32 AC 74 ms
14,664 KB
testcase_33 AC 53 ms
12,516 KB
testcase_34 AC 92 ms
15,188 KB
testcase_35 AC 16 ms
8,496 KB
testcase_36 AC 26 ms
9,576 KB
testcase_37 AC 17 ms
8,476 KB
testcase_38 AC 17 ms
8,800 KB
testcase_39 AC 29 ms
10,452 KB
testcase_40 AC 17 ms
8,680 KB
testcase_41 AC 15 ms
8,492 KB
testcase_42 AC 14 ms
8,348 KB
testcase_43 AC 17 ms
9,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
c=int(input())
v=int(input())
S=[int(i) for i in input().split()]
T=[int(i) for i in input().split()]
Y=[int(i) for i in input().split()]
M=[int(i) for i in input().split()]
nc=n*(c+1)
edge = [[] for i in range(nc)]
for i in range(v):
  s,t,y,m=S[i],T[i],Y[i],M[i]
  for j in range(y,c+1):
    edge[s-1+j*n].append(m*10**6+t-1+(j-y)*n)

import heapq
def dijkstra_heap(s):
  d=[float("inf")]*nc
  used=[True]*nc
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(n*c)
ans=D[n-1]
for i in range(c):
  ans=min(ans,D[n-1+(i+1)*n])
if ans==float("inf"):
  print(-1)
else:
  print(ans)
0