結果
問題 | No.614 壊れたキャンパス |
ユーザー | hatoo |
提出日時 | 2018-01-12 19:58:18 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,284 bytes |
コンパイル時間 | 12,984 ms |
コンパイル使用メモリ | 400,616 KB |
実行使用メモリ | 26,832 KB |
最終ジャッジ日時 | 2024-06-06 10:08:18 |
合計ジャッジ時間 | 15,129 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | AC | 146 ms
18,920 KB |
testcase_10 | AC | 65 ms
16,540 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 50 ms
14,052 KB |
testcase_16 | WA | - |
testcase_17 | AC | 83 ms
26,832 KB |
testcase_18 | AC | 63 ms
14,940 KB |
testcase_19 | WA | - |
コンパイルメッセージ
warning: unused variable: `k` --> src/main.rs:37:16 | 37 | let (n, m, k, s, t) = get!(usize, usize, i64, i64, i64); | ^ help: if this is intentional, prefix it with an underscore: `_k` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::stdin; mod util { use std::io::stdin; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } fn main() { let (n, m, k, s, t) = get!(usize, usize, i64, i64, i64); let abc = get!(usize, i64, i64; m); let mut edges = vec![Vec::new(); n - 1]; for &(a, b, c) in &abc { edges[a - 1].push((b, c)); } let mut dp = BTreeMap::new(); dp.insert(s, 0); for es in edges.iter_mut() { if es.is_empty() { println!("-1"); return; } es.sort(); let v: Vec<(i64, i64)> = dp.into_iter().collect(); dp = BTreeMap::new(); let mut i = v.len(); let mut cost = i64::max_value() / 4; for &(b, c) in es.iter().rev() { while i > 0 && v[i - 1].0 >= b { i -= 1; cost = min(cost, v[i].0 + v[i].1); } dp.insert(c, cost - b); } let mut i = 0; let mut cost = i64::max_value() / 4; for &(b, c) in es.iter().rev() { while i < v.len() && v[i].0 <= b { cost = min(cost, v[i].1 - v[i].0); i += 1; } let nc = cost + b; let v = dp.entry(c).or_insert(nc); *v = min(*v, nc); } } println!( "{}", dp.into_iter() .map(|(p, c)| c + (t - p).abs()) .min() .unwrap() ); }