結果
問題 | No.2157 崖 |
ユーザー | koba-e964 |
提出日時 | 2023-06-13 11:48:48 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 4,528 ms / 6,000 ms |
コード長 | 2,821 bytes |
コンパイル時間 | 28,038 ms |
コンパイル使用メモリ | 383,940 KB |
実行使用メモリ | 17,920 KB |
最終ジャッジ日時 | 2024-06-13 00:12:40 |
合計ジャッジ時間 | 54,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 3,939 ms
12,288 KB |
testcase_14 | AC | 3,418 ms
16,640 KB |
testcase_15 | AC | 3,592 ms
12,160 KB |
testcase_16 | AC | 3,644 ms
12,288 KB |
testcase_17 | AC | 2,757 ms
14,464 KB |
testcase_18 | AC | 2,640 ms
14,080 KB |
testcase_19 | AC | 4,528 ms
14,720 KB |
testcase_20 | AC | 3,550 ms
17,920 KB |
testcase_21 | AC | 3,859 ms
17,920 KB |
testcase_22 | AC | 2,823 ms
13,440 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 3 ms
6,944 KB |
コンパイルメッセージ
warning: unused import: `BufWriter` --> src/main.rs:5:22 | 5 | use std::io::{Write, BufWriter}; | ^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `Write` --> src/main.rs:5:15 | 5 | use std::io::{Write, BufWriter}; | ^^^^^
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // 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 ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Bisect<T> { fn lower_bound(&self, val: &T) -> usize; fn upper_bound(&self, val: &T) -> usize; } impl<T: Ord> Bisect<T> for [T] { fn lower_bound(&self, val: &T) -> usize { let mut pass = self.len() + 1; let mut fail = 0; while pass - fail > 1 { let mid = (pass + fail) / 2; if &self[mid - 1] >= val { pass = mid; } else { fail = mid; } } pass - 1 } fn upper_bound(&self, val: &T) -> usize { let mut pass = self.len() + 1; let mut fail = 0; while pass - fail > 1 { let mid = (pass + fail) / 2; if &self[mid - 1] > val { pass = mid; } else { fail = mid; } } pass - 1 } } fn main() { input! { n: usize, m: usize, d: [[i64; m]; n], } let mut d = d; for i in 0..n { d[i].sort_unstable(); } const INF: i64 = 1 << 30; let mut pass = INF; let mut fail = -1; while pass - fail > 1 { let mid = (pass + fail) / 2; let mut acc = vec![0; m + 1]; for i in 0..m { acc[i + 1] = acc[i] + 1; } for i in 1..n { let mut bcc = vec![0; m + 1]; for j in 0..m { let lo = d[i - 1].lower_bound(&(d[i][j] - mid)); let hi = d[i - 1].upper_bound(&d[i][j]); bcc[j + 1] = bcc[j] + if acc[lo] < acc[hi] { 1 } else { 0 }; } acc = bcc; } if acc[m] > 0 { pass = mid; } else { fail = mid; } } println!("{}", if pass >= INF { -1 } else { pass }); }