結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
sue_charo
|
| 提出日時 | 2017-04-21 18:13:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,524 bytes |
| コンパイル時間 | 69 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2024-07-08 04:51:38 |
| 合計ジャッジ時間 | 7,068 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 1 -- * 32 |
ソースコード
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
def solve(N, C, V, S, T, Y, M):
graph = [[] for __ in range(N + 1)]
for s, t, y, m in zip(S, T, Y, M):
graph[s].append((t, y, m))
dp = collections.defaultdict(lambda: INF)
dp[(1, C)] = 0
city_queue = collections.deque([(1, C)])
while city_queue:
city_money = city_queue.pop()
l_next = graph[city_money[0]]
if len(l_next) == 0:
continue
for next in l_next:
now_time = dp[(city_money)]
next_time = now_time + next[2]
next_money = city_money[1] - next[1]
next_city = next[0]
if next_money < 0:
continue
dp[(next_city, next_money)] = min(next_time, dp[(next_city, next_money)])
collections.deque.append(city_queue, (next_city, next_money))
ans = INF
for i in range(C + 1):
ans = min(ans, dp[(N, i)])
if ans == INF:
ans = -1
return ans
def main():
N = II()
C = II()
V = II()
S = [0] + ILI()
T = [0] + ILI()
Y = [0] + ILI()
M = [0] + ILI()
print(solve(N, C, V, S, T, Y, M))
if __name__ == "__main__":
main()
sue_charo