結果
問題 | No.1557 Binary Variable |
ユーザー | koba-e964 |
提出日時 | 2021-10-15 08:17:54 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 359 ms / 2,000 ms |
コード長 | 2,871 bytes |
コンパイル時間 | 13,136 ms |
コンパイル使用メモリ | 403,556 KB |
実行使用メモリ | 54,620 KB |
最終ジャッジ日時 | 2024-09-17 16:41:32 |
合計ジャッジ時間 | 23,281 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
29,956 KB |
testcase_01 | AC | 199 ms
34,124 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 109 ms
15,420 KB |
testcase_05 | AC | 109 ms
15,680 KB |
testcase_06 | AC | 104 ms
15,936 KB |
testcase_07 | AC | 108 ms
15,808 KB |
testcase_08 | AC | 121 ms
15,812 KB |
testcase_09 | AC | 123 ms
15,920 KB |
testcase_10 | AC | 151 ms
18,404 KB |
testcase_11 | AC | 152 ms
18,620 KB |
testcase_12 | AC | 121 ms
15,936 KB |
testcase_13 | AC | 156 ms
19,264 KB |
testcase_14 | AC | 317 ms
46,664 KB |
testcase_15 | AC | 163 ms
20,160 KB |
testcase_16 | AC | 301 ms
44,096 KB |
testcase_17 | AC | 265 ms
37,488 KB |
testcase_18 | AC | 241 ms
33,108 KB |
testcase_19 | AC | 336 ms
53,460 KB |
testcase_20 | AC | 330 ms
52,268 KB |
testcase_21 | AC | 333 ms
52,172 KB |
testcase_22 | AC | 337 ms
53,244 KB |
testcase_23 | AC | 334 ms
52,100 KB |
testcase_24 | AC | 343 ms
53,876 KB |
testcase_25 | AC | 339 ms
53,852 KB |
testcase_26 | AC | 342 ms
54,300 KB |
testcase_27 | AC | 335 ms
54,200 KB |
testcase_28 | AC | 341 ms
54,340 KB |
testcase_29 | AC | 359 ms
54,504 KB |
testcase_30 | AC | 351 ms
54,428 KB |
testcase_31 | AC | 350 ms
54,620 KB |
testcase_32 | AC | 346 ms
54,424 KB |
testcase_33 | AC | 327 ms
51,196 KB |
testcase_34 | AC | 1 ms
6,944 KB |
testcase_35 | AC | 1 ms
6,944 KB |
testcase_36 | AC | 1 ms
6,940 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; use std::collections::*; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } // Tags: dual-of-linar-programming fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn solve() { input! { n: i64, m: usize, lr: [(i64, i64); m], } let mut coo = vec![]; for &(l, r) in &lr { coo.push(l - 1); coo.push(r); } coo.push(0); coo.push(n); coo.sort(); coo.dedup(); let k = coo.len(); const INF: i64 = 1 << 50; let mut dist = vec![INF; k]; let mut g = vec![vec![]; k]; for i in 0..k - 1 { g[i + 1].push((i, 0)); g[i].push((i + 1, coo[i + 1] - coo[i])); } for &(l, r) in &lr { let l = coo.binary_search(&(l - 1)).unwrap(); let r = coo.binary_search(&r).unwrap(); g[l].push((r, coo[r] - coo[l] - 1)); } let mut que = BinaryHeap::new(); que.push((Reverse(0), 0)); while let Some((Reverse(d), v)) = que.pop() { if dist[v] <= d { continue; } dist[v] = d; for &(w, c) in &g[v] { que.push((Reverse(d + c), w)); } } println!("{}", dist[k - 1]); }