結果
問題 | No.2739 Time is money |
ユーザー | Yukino DX. |
提出日時 | 2024-04-26 22:40:31 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 2,039 bytes |
コンパイル時間 | 14,182 ms |
コンパイル使用メモリ | 379,728 KB |
実行使用メモリ | 35,584 KB |
最終ジャッジ日時 | 2024-11-14 14:29:23 |
合計ジャッジ時間 | 20,055 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 56 ms
21,384 KB |
testcase_03 | AC | 128 ms
27,028 KB |
testcase_04 | AC | 45 ms
20,600 KB |
testcase_05 | AC | 79 ms
19,688 KB |
testcase_06 | AC | 99 ms
24,484 KB |
testcase_07 | AC | 166 ms
35,584 KB |
testcase_08 | AC | 160 ms
35,324 KB |
testcase_09 | AC | 166 ms
34,916 KB |
testcase_10 | AC | 93 ms
34,580 KB |
testcase_11 | AC | 167 ms
34,884 KB |
testcase_12 | AC | 109 ms
34,960 KB |
testcase_13 | AC | 110 ms
35,044 KB |
testcase_14 | AC | 106 ms
34,184 KB |
testcase_15 | AC | 70 ms
29,520 KB |
testcase_16 | AC | 71 ms
27,200 KB |
testcase_17 | AC | 167 ms
33,404 KB |
testcase_18 | AC | 163 ms
34,452 KB |
testcase_19 | AC | 90 ms
29,756 KB |
ソースコード
#![allow(unused_imports)] //use itertools::{iproduct, Itertools}; use proconio::input; use proconio::marker::*; use std::collections::*; fn main() { input! { n:usize, m:usize, x:usize, uvct:[(Usize1,Usize1,usize,usize);m], } let mut g = vec![vec![]; n]; for &(u, v, c, t) in uvct.iter() { g[u].push((v, t * x + c)); g[v].push((u, t * x + c)); } let neigh = |crr_pos: usize, crr_dist: usize| { let mut nxts = vec![]; for &(nxt, cost) in g[crr_pos].iter() { nxts.push((nxt, crr_dist + cost)); } nxts }; let dists = Dijkstra::new(neigh).solve(n, 0); if dists[n - 1] == INF { println!("-1"); } else { let ans = (dists[n - 1] + x - 1) / x; println!("{}", ans); } } const INF: usize = std::usize::MAX; use dijkstra::*; mod dijkstra { use std::cmp::Reverse; pub struct Dijkstra<F> where F: Fn(usize, usize) -> Vec<(usize, usize)>, //(crr_pos,crr_dist)->Vec<(nxt_pos,nxt_dist)> { neigh: F, } impl<F> Dijkstra<F> where F: Fn(usize, usize) -> Vec<(usize, usize)>, { pub fn new(neigh: F) -> Self { Self { neigh } } pub fn solve(&self, n: usize, start: usize) -> Vec<usize> { let mut dists = vec![INF; n]; dists[start] = 0; let mut pq = std::collections::BinaryHeap::new(); pq.push(Reverse((0, start))); while let Some(Reverse((crr_dist, crr_pos))) = pq.pop() { if dists[crr_pos] < crr_dist { continue; } for (nxt_pos, nxt_dist) in (self.neigh)(crr_pos, crr_dist) { if nxt_dist < dists[nxt_pos] { dists[nxt_pos] = nxt_dist; pq.push(Reverse((nxt_dist, nxt_pos))); } } } dists } } const INF: usize = std::usize::MAX; }