結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | mai |
提出日時 | 2021-04-23 01:18:04 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 221 ms / 2,000 ms |
コード長 | 2,583 bytes |
コンパイル時間 | 14,947 ms |
コンパイル使用メモリ | 380,424 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-07-04 06:38:16 |
合計ジャッジ時間 | 17,330 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 221 ms
11,904 KB |
testcase_03 | AC | 155 ms
10,112 KB |
testcase_04 | AC | 91 ms
7,552 KB |
testcase_05 | AC | 60 ms
6,940 KB |
testcase_06 | AC | 126 ms
10,368 KB |
testcase_07 | AC | 127 ms
12,544 KB |
testcase_08 | AC | 173 ms
12,544 KB |
testcase_09 | AC | 111 ms
12,544 KB |
testcase_10 | AC | 45 ms
6,944 KB |
testcase_11 | AC | 51 ms
7,552 KB |
testcase_12 | AC | 47 ms
6,940 KB |
testcase_13 | AC | 29 ms
6,944 KB |
testcase_14 | AC | 21 ms
6,940 KB |
testcase_15 | AC | 41 ms
6,940 KB |
testcase_16 | AC | 43 ms
6,940 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 7 ms
6,944 KB |
testcase_19 | AC | 41 ms
6,944 KB |
testcase_20 | AC | 66 ms
9,344 KB |
testcase_21 | AC | 81 ms
7,808 KB |
testcase_22 | AC | 57 ms
10,112 KB |
testcase_23 | AC | 51 ms
9,728 KB |
testcase_24 | AC | 45 ms
8,960 KB |
testcase_25 | AC | 71 ms
9,892 KB |
testcase_26 | AC | 71 ms
9,728 KB |
testcase_27 | AC | 25 ms
6,944 KB |
testcase_28 | AC | 106 ms
12,416 KB |
testcase_29 | AC | 80 ms
8,448 KB |
testcase_30 | AC | 110 ms
9,344 KB |
testcase_31 | AC | 93 ms
12,160 KB |
testcase_32 | AC | 86 ms
10,624 KB |
testcase_33 | AC | 58 ms
8,960 KB |
testcase_34 | AC | 25 ms
6,944 KB |
testcase_35 | AC | 33 ms
6,940 KB |
testcase_36 | AC | 72 ms
7,040 KB |
testcase_37 | AC | 63 ms
9,088 KB |
testcase_38 | AC | 11 ms
6,940 KB |
testcase_39 | AC | 45 ms
6,940 KB |
testcase_40 | AC | 45 ms
6,944 KB |
testcase_41 | AC | 38 ms
6,940 KB |
testcase_42 | AC | 39 ms
6,940 KB |
testcase_43 | AC | 54 ms
9,088 KB |
testcase_44 | AC | 54 ms
8,960 KB |
testcase_45 | AC | 53 ms
9,116 KB |
testcase_46 | AC | 74 ms
8,064 KB |
testcase_47 | AC | 95 ms
9,344 KB |
testcase_48 | AC | 93 ms
9,088 KB |
コンパイルメッセージ
warning: unused import: `ops::Sub` --> src/main.rs:1:37 | 1 | use std::{collections::*, io::Read, ops::Sub}; | ^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
ソースコード
use std::{collections::*, io::Read, ops::Sub}; fn take_token<R: std::io::BufRead>(cin: &mut R) -> String { cin.bytes() .map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::<String>() } #[allow(unused)] macro_rules! scan { ($io:expr => $t:ty) => (take_token(&mut $io).parse::<$t>().unwrap()); ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>()); ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*)); ($io:expr => $($t:tt),* * $n:expr) => ((0..$n).map(|_| ($(scan!($io => $t)),*)).collect::<Vec<_>>()); } struct Graph<T: Clone = ()>(Vec<Vec<(usize, T)>>); impl<T: Clone> Graph<T> { fn to<'a>(&self, i: usize) -> &Vec<(usize, T)> { &(self.0)[i] } } struct GraphBuilder<T: Clone = ()>(Graph<T>); impl<T: Clone> GraphBuilder<T> { fn new(n: usize) -> Self { Self(Graph::<T>(vec![Vec::<(usize, T)>::new(); n])) } fn connect(&mut self, u: usize, v: usize, item: T) { (self.0 .0)[u].push((v, item.clone())); (self.0 .0)[v].push((u, item)); } fn build(self) -> Graph<T> { self.0 } } fn binary_search<F: Fn(i64) -> bool>(ok_val: i64, ng_val: i64, check: F) -> i64 { let mut ok = ok_val; let mut ng = ng_val; while (ok - ng).abs() > 1 { let m = (ok + ng) / 2; if check(m) { ok = m; } else { ng = m; } } ok } fn main() { solve(std::io::stdin().lock()) } fn calc(graph: &Graph<i32>, n: usize, k: i32) -> Option<i32> { let mut visited = vec![0; n as usize]; let mut que = VecDeque::<usize>::new(); que.push_back(0); while let Some(v) = que.pop_front() { let d = visited[v]; if v == n - 1 { return Some(d); } for (v2, cap) in graph.to(v).iter() { if *cap < k || visited[*v2] > 0 { continue; } visited[*v2] = d + 1; que.push_back(*v2); } } None } fn solve<R: std::io::BufRead>(mut cin: R) { let (n, m) = scan!(cin => i32, i32); let mut builder = GraphBuilder::<i32>::new(n as usize); for _ in 0..m { let (u, v, m) = scan!(cin => i32, i32, i32); builder.connect((u - 1) as usize, (v - 1) as usize, m); } let graph = builder.build(); let k = binary_search(0, (2e9) as i64, |m| { calc(&graph, n as usize, m as i32).is_some() }) as i32; println!("{} {}", k, calc(&graph, n as usize, k).unwrap()); }