結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2025-09-04 21:38:51 |
言語 | Crystal (1.14.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 665 bytes |
コンパイル時間 | 14,972 ms |
コンパイル使用メモリ | 308,628 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-04 21:39:29 |
合計ジャッジ時間 | 13,980 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 40 |
ソースコード
n = read_line.to_i c = read_line.to_i v = read_line.to_i graph = Array.new(n) { [] of Tuple(Int32, Int32, Int32) } v.times do s, t, y, m = read_line.split.map(&.to_i) graph[s - 1] << {t - 1, y, m} end INF = 1_000_000_000 dp = Array.new(c + 1, INF) dp[c] = 0 n.times do |i| temp = dp.dup edges = graph[i] c.downto(0) do |k| current_time = temp[k] next if current_time == INF edges.each do |to, cost, time| next if k < cost new_k = k - cost new_time = current_time + time if new_time < dp[new_k] dp[new_k] = new_time end end end end result = dp.min puts result == INF ? -1 : result