結果
問題 | No.1 道のショートカット |
ユーザー | terasa |
提出日時 | 2022-11-03 15:48:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 192 ms / 5,000 ms |
コード長 | 2,524 bytes |
コンパイル時間 | 799 ms |
コンパイル使用メモリ | 82,076 KB |
実行使用メモリ | 90,612 KB |
最終ジャッジ日時 | 2024-07-18 00:56:03 |
合計ジャッジ時間 | 6,096 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
68,776 KB |
testcase_01 | AC | 58 ms
69,044 KB |
testcase_02 | AC | 59 ms
68,784 KB |
testcase_03 | AC | 59 ms
68,404 KB |
testcase_04 | AC | 58 ms
68,604 KB |
testcase_05 | AC | 59 ms
68,652 KB |
testcase_06 | AC | 59 ms
68,944 KB |
testcase_07 | AC | 60 ms
69,336 KB |
testcase_08 | AC | 138 ms
86,992 KB |
testcase_09 | AC | 99 ms
82,464 KB |
testcase_10 | AC | 124 ms
81,176 KB |
testcase_11 | AC | 136 ms
82,932 KB |
testcase_12 | AC | 192 ms
90,612 KB |
testcase_13 | AC | 190 ms
90,308 KB |
testcase_14 | AC | 77 ms
78,748 KB |
testcase_15 | AC | 62 ms
70,592 KB |
testcase_16 | AC | 81 ms
79,156 KB |
testcase_17 | AC | 61 ms
70,324 KB |
testcase_18 | AC | 79 ms
78,672 KB |
testcase_19 | AC | 82 ms
79,016 KB |
testcase_20 | AC | 121 ms
81,084 KB |
testcase_21 | AC | 90 ms
79,324 KB |
testcase_22 | AC | 80 ms
78,948 KB |
testcase_23 | AC | 164 ms
87,332 KB |
testcase_24 | AC | 172 ms
89,208 KB |
testcase_25 | AC | 128 ms
81,944 KB |
testcase_26 | AC | 114 ms
80,804 KB |
testcase_27 | AC | 175 ms
86,776 KB |
testcase_28 | AC | 68 ms
73,624 KB |
testcase_29 | AC | 103 ms
78,628 KB |
testcase_30 | AC | 83 ms
78,636 KB |
testcase_31 | AC | 89 ms
79,080 KB |
testcase_32 | AC | 139 ms
84,676 KB |
testcase_33 | AC | 117 ms
82,772 KB |
testcase_34 | AC | 157 ms
85,752 KB |
testcase_35 | AC | 86 ms
78,652 KB |
testcase_36 | AC | 97 ms
78,860 KB |
testcase_37 | AC | 87 ms
78,668 KB |
testcase_38 | AC | 69 ms
74,724 KB |
testcase_39 | AC | 76 ms
79,172 KB |
testcase_40 | AC | 79 ms
78,796 KB |
testcase_41 | AC | 65 ms
72,444 KB |
testcase_42 | AC | 60 ms
68,940 KB |
testcase_43 | AC | 60 ms
70,272 KB |
ソースコード
from typing import List, Tuple, Optional import sys import itertools import heapq import bisect from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline # for AtCoder Easy test if __file__ != 'prog.py': # sys.setrecursionlimit(10 ** 6) pass def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input().rstrip() class Dijkstra: def __init__(self, N: int, E: List[List[Tuple[int, int]]], start: int = 0, inf: int = 1 << 50): self.N = N self.E = E self.start = start self.inf = inf self.C = [self.inf] * N # self.prev = [None] * N self._calculate() def get_cost(self, i: int) -> Optional[int]: """return cost to i-th vertex if reachable otherwise None""" return self.C[i] if self.reachable(i) else self.inf def get_path(self, i) -> Optional[List[int]]: """return shortest path to i-th vertex if reachable otherwise None""" if not self.reachable(i): return None p = [] cur = i while cur is not None: p.append(cur) cur = self.prev[cur] p.reverse() return p def reachable(self, i) -> bool: """return whether i-th vertex from start is reachable""" return self.C[i] < self.inf def _calculate(self) -> None: h = [(0, self.start)] self.C[self.start] = 0 visited = [False] * self.N while h: _, v = heapq.heappop(h) if visited[v] is True: continue visited[v] = True for c, d in self.E[v]: if self.C[d] > self.C[v] + c: self.C[d] = self.C[v] + c # self.prev[d] = v heapq.heappush(h, (self.C[d], d)) N = int(input()) C = int(input()) V = int(input()) S = list(map(lambda x: int(x) - 1, input().split())) T = list(map(lambda x: int(x) - 1, input().split())) Y = readlist() M = readlist() E = [[] for _ in range(N * (C + 1))] for i in range(V): for j in range(C, 0, -1): def h(v, c): return v * (C + 1) + c if j - Y[i] < 0: break E[h(S[i], j)].append((M[i], h(T[i], j - Y[i]))) solver = Dijkstra(N * (C + 1), E, start=C) ans = solver.inf for j in range(C + 1): ans = min(ans, solver.get_cost((N - 1) * (C + 1) + j)) print(ans if ans < solver.inf else -1)