結果
問題 | No.2157 崖 |
ユーザー | nephrologist |
提出日時 | 2022-12-16 14:29:23 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,421 ms / 6,000 ms |
コード長 | 3,446 bytes |
コンパイル時間 | 14,482 ms |
コンパイル使用メモリ | 378,628 KB |
実行使用メモリ | 93,952 KB |
最終ジャッジ日時 | 2024-11-15 19:47:30 |
合計ジャッジ時間 | 29,860 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 809 ms
61,880 KB |
testcase_14 | AC | 1,195 ms
86,964 KB |
testcase_15 | AC | 1,047 ms
61,312 KB |
testcase_16 | AC | 1,066 ms
61,952 KB |
testcase_17 | AC | 1,012 ms
74,588 KB |
testcase_18 | AC | 1,009 ms
72,584 KB |
testcase_19 | AC | 1,059 ms
76,160 KB |
testcase_20 | AC | 1,421 ms
93,952 KB |
testcase_21 | AC | 1,390 ms
93,952 KB |
testcase_22 | AC | 993 ms
69,888 KB |
testcase_23 | AC | 1 ms
5,248 KB |
testcase_24 | AC | 7 ms
5,248 KB |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:8:13 | 8 | let mut s = { | ----^ | | | help: remove this `mut` ... 52 | input!(n: usize, m: usize, D: [[i128; m]; n]); | --------------------------------------------- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info) warning: variable `D` should have a snake case name --> src/main.rs:52:32 | 52 | input!(n: usize, m: usize, D: [[i128; m]; n]); | ^ help: convert the identifier to snake case: `d` | = note: `#[warn(non_snake_case)]` on by default
ソースコード
//proconio macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut 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, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } fn main() { input!(n: usize, m: usize, D: [[i128; m]; n]); let mut memo = Vec::new(); for i in 0..n { let mut temp = Vec::new(); for j in 0..m { temp.push(D[i][j]) } temp.sort(); // println!("temp, {:?}", &temp); memo.push(temp); } // std::process::exit(0); let mut ok = 1000_000_000_0; let mut ng = -1; while ok - ng > 1 { let mid = (ok + ng) / 2; if check(mid, n, m, &memo) { ok = mid; } else { ng = mid; } } // eprintln!("ok {}", ok); // eprintln!("ng {}", ng); if ok > 1000_000_000 { ok = -1; } println!("{}", ok); } fn check(x: i128, n: usize, m: usize, memo: &Vec<Vec<i128>>) -> bool { // eprintln!("x {}", x); let mut res = false; let mut dp = vec![vec![false; m]; n]; for j in 0..m { dp[0][j] = true; } for i in 0..n - 1 { let ni = i + 1; let mut left = 0; let mut right = 0; let mut flagnums = vec![0; m + 1]; for j in 0..m { if !dp[i][j] { continue; } let preval = memo[i][j]; while (left < m - 1) & (memo[ni][left] < preval) { left += 1; } // 遷移不可能 if (left == m - 1) & (memo[ni][left] < preval) { break; } // right = right.max(left); while right < m { if memo[ni][right] <= preval + x { right += 1; } else { break; } } // eprintln!("i j left right {} {} {} {}", i, j, left, right); flagnums[left] += 1; flagnums[right] -= 1; // eprintln!("flag {:?}", flagnums); } for j in 0..m { flagnums[j + 1] += flagnums[j]; } // eprintln!("flag {:?}", flagnums); for j in 0..m { if flagnums[j] > 0 { dp[ni][j] = true; } } } for j in 0..m { if dp[n - 1][j] { res = true; // eprintln!("hoge"); break; } } res }