結果
問題 | No.1607 Kth Maximum Card |
ユーザー | akakimidori |
提出日時 | 2021-07-16 21:55:03 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,942 ms / 3,500 ms |
コード長 | 3,132 bytes |
コンパイル時間 | 16,037 ms |
コンパイル使用メモリ | 403,248 KB |
実行使用メモリ | 31,628 KB |
最終ジャッジ日時 | 2024-07-06 09:02:41 |
合計ジャッジ時間 | 32,982 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 0 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 0 ms
6,940 KB |
testcase_08 | AC | 1,461 ms
31,448 KB |
testcase_09 | AC | 1,126 ms
26,068 KB |
testcase_10 | AC | 1,653 ms
31,628 KB |
testcase_11 | AC | 127 ms
8,832 KB |
testcase_12 | AC | 1,077 ms
24,960 KB |
testcase_13 | AC | 79 ms
6,940 KB |
testcase_14 | AC | 98 ms
7,584 KB |
testcase_15 | AC | 698 ms
24,060 KB |
testcase_16 | AC | 78 ms
6,940 KB |
testcase_17 | AC | 24 ms
6,940 KB |
testcase_18 | AC | 340 ms
17,096 KB |
testcase_19 | AC | 181 ms
11,264 KB |
testcase_20 | AC | 269 ms
13,880 KB |
testcase_21 | AC | 287 ms
14,996 KB |
testcase_22 | AC | 1,698 ms
31,472 KB |
testcase_23 | AC | 1,671 ms
31,404 KB |
testcase_24 | AC | 228 ms
11,444 KB |
testcase_25 | AC | 128 ms
7,908 KB |
testcase_26 | AC | 163 ms
9,044 KB |
testcase_27 | AC | 251 ms
11,836 KB |
testcase_28 | AC | 196 ms
10,052 KB |
testcase_29 | AC | 630 ms
19,488 KB |
testcase_30 | AC | 1,942 ms
30,984 KB |
testcase_31 | AC | 574 ms
17,748 KB |
testcase_32 | AC | 213 ms
20,316 KB |
testcase_33 | AC | 229 ms
20,256 KB |
testcase_34 | AC | 208 ms
20,208 KB |
testcase_35 | AC | 193 ms
20,272 KB |
コンパイルメッセージ
warning: unused import: `std::io::Write` --> src/main.rs:72:5 | 72 | use std::io::Write; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: type alias `Map` is never used --> src/main.rs:75:6 | 75 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:76:6 | 76 | type Set<T> = BTreeSet<T>; | ^^^
ソースコード
// ---------- 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::io::Write; use std::collections::*; type Map<K, V> = BTreeMap<K, V>; type Set<T> = BTreeSet<T>; type Deque<T> = VecDeque<T>; fn run() { input! { n: usize, m: usize, k: u32, e: [(usize1, usize1, u32); m], } let valid = |m: u32| -> bool { let mut g = vec![vec![]; n]; for &(a, b, c) in e.iter() { let c = if c >= m {1} else {0}; g[a].push((b, c)); g[b].push((a, c)); } let mut dp = vec![k + 1; n]; dp[0] = 0; let mut deq = Deque::new(); deq.push_back(0); while let Some(v) = deq.pop_front() { let d = dp[v]; for &(u, c) in g[v].iter() { if c == 0 && dp[u].chmin(d) { deq.push_front(u); } if c == 1 && 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(); }