結果
問題 |
No.1715 Dinner 2
|
ユーザー |
![]() |
提出日時 | 2021-10-22 23:42:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,090 bytes |
コンパイル時間 | 11,732 ms |
コンパイル使用メモリ | 400,964 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 06:38:14 |
合計ジャッジ時間 | 13,027 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 35 WA * 3 |
コンパイルメッセージ
warning: unused variable: `i` --> src/main.rs:23:9 | 23 | for i in 0..n { | ^ help: if this is intentional, prefix it with an underscore: `_i` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `ng` --> src/main.rs:54:14 | 54 | let (ok, ng) = binary_search(-(d as i64) * 100000000 - 1, 0, criterion); | ^^ help: if this is intentional, prefix it with an underscore: `_ng`
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<usize>(); let (n, d) = (v[0], v[1]); let mut negs = vec![]; for i in 0..n { let v = read_vec::<i64>(); let (p, q) = (v[0], v[1]); negs.push((p, q)); } negs.sort_by_key(|&(p, q)| q - p); negs.reverse(); let criterion = |mid: i64| -> bool { let mut used = n; let mut cur = 0; for _ in 0..d { let mut found = false; for (i, &(p, q)) in negs.iter().enumerate() { if i == used { continue; } if cur - p >= mid { cur += q - p; found = true; used = i; break; } } if cur < mid || !found { return false; } } true }; let (ok, ng) = binary_search(-(d as i64) * 100000000 - 1, 0, criterion); println!("{}", ok); } type Input = i64; fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input) where F: Fn(Input) -> bool, { assert_eq!(criterion(lb), true); assert_eq!(criterion(ub), false); let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid) { ok = mid; } else { ng = mid; } } (ok, ng) } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }