結果
問題 | No.1607 Kth Maximum Card |
ユーザー | akakimidori |
提出日時 | 2021-07-16 23:27:00 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 673 ms / 3,500 ms |
コード長 | 3,053 bytes |
コンパイル時間 | 1,018 ms |
コンパイル使用メモリ | 149,336 KB |
実行使用メモリ | 32,028 KB |
最終ジャッジ日時 | 2023-09-20 15:58:35 |
合計ジャッジ時間 | 8,694 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,384 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 422 ms
31,988 KB |
testcase_09 | AC | 411 ms
27,456 KB |
testcase_10 | AC | 533 ms
32,028 KB |
testcase_11 | AC | 41 ms
9,280 KB |
testcase_12 | AC | 365 ms
26,548 KB |
testcase_13 | AC | 33 ms
6,556 KB |
testcase_14 | AC | 37 ms
7,672 KB |
testcase_15 | AC | 298 ms
24,360 KB |
testcase_16 | AC | 29 ms
6,848 KB |
testcase_17 | AC | 11 ms
4,380 KB |
testcase_18 | AC | 122 ms
18,424 KB |
testcase_19 | AC | 71 ms
11,736 KB |
testcase_20 | AC | 118 ms
13,672 KB |
testcase_21 | AC | 123 ms
16,804 KB |
testcase_22 | AC | 554 ms
31,680 KB |
testcase_23 | AC | 559 ms
31,684 KB |
testcase_24 | AC | 159 ms
12,048 KB |
testcase_25 | AC | 63 ms
8,152 KB |
testcase_26 | AC | 105 ms
9,200 KB |
testcase_27 | AC | 206 ms
12,316 KB |
testcase_28 | AC | 139 ms
10,004 KB |
testcase_29 | AC | 302 ms
20,972 KB |
testcase_30 | AC | 673 ms
30,560 KB |
testcase_31 | AC | 317 ms
17,388 KB |
testcase_32 | AC | 60 ms
21,416 KB |
testcase_33 | AC | 60 ms
21,424 KB |
testcase_34 | AC | 59 ms
21,464 KB |
testcase_35 | AC | 56 ms
21,564 KB |
ソースコード
// ---------- begin chmin, chmax ---------- pub trait ChangeMinMax { fn chmin(&mut self, x: Self) -> bool; fn chmax(&mut self, x: Self) -> bool; } impl<T: PartialOrd> ChangeMinMax for T { fn chmin(&mut self, x: Self) -> bool { *self > x && { *self = x; true } } fn chmax(&mut self, x: Self) -> bool { *self < x && { *self = x; true } } } // ---------- end chmin, chmax ---------- // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::collections::*; type Deque<T> = VecDeque<T>; fn run() { input! { n: usize, m: usize, k: u32, e: [(usize1, usize1, u32); m], } let mut g = vec![vec![]; n]; for &(a, b, c) in e.iter() { g[a].push((b, c)); g[b].push((a, c)); } let mut dp = vec![k + 1; n]; let mut deq = Deque::new(); let mut valid = |m: u32| -> bool { dp.clear(); deq.clear(); dp.resize(n, k + 1); dp[0] = 0; deq.push_back(0); while let Some(v) = deq.pop_front() { let d = dp[v]; for &(u, c) in g[v].iter() { if c < m && dp[u].chmin(d) { deq.push_front(u); } if c >= m && dp[u].chmin(d + 1) { deq.push_back(u); } } } dp[n - 1] < k }; let mut ng = 0; let mut ok = 200001; while ok - ng > 1 { let mid = (ok + ng) / 2; if valid(mid) { ok = mid; } else { ng = mid; } } println!("{}", ng); } fn main() { run(); }