結果
問題 | No.934 Explosive energy drink |
ユーザー | fukafukatani |
提出日時 | 2019-11-29 23:07:38 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,890 bytes |
コンパイル時間 | 26,568 ms |
コンパイル使用メモリ | 378,768 KB |
実行使用メモリ | 25,844 KB |
平均クエリ数 | 507.67 |
最終ジャッジ日時 | 2024-07-16 18:47:22 |
合計ジャッジ時間 | 20,737 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
24,964 KB |
testcase_01 | AC | 26 ms
24,964 KB |
testcase_02 | WA | - |
testcase_03 | AC | 28 ms
24,836 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 20 ms
25,220 KB |
testcase_07 | AC | 19 ms
24,580 KB |
testcase_08 | AC | 21 ms
24,964 KB |
testcase_09 | AC | 21 ms
24,836 KB |
testcase_10 | AC | 21 ms
24,964 KB |
testcase_11 | AC | 21 ms
25,220 KB |
testcase_12 | AC | 26 ms
24,964 KB |
testcase_13 | AC | 44 ms
24,964 KB |
testcase_14 | AC | 79 ms
24,964 KB |
testcase_15 | RE | - |
testcase_16 | AC | 22 ms
25,324 KB |
testcase_17 | AC | 26 ms
24,964 KB |
testcase_18 | WA | - |
testcase_19 | AC | 27 ms
25,220 KB |
testcase_20 | WA | - |
testcase_21 | AC | 33 ms
25,220 KB |
testcase_22 | AC | 56 ms
24,836 KB |
testcase_23 | AC | 38 ms
24,580 KB |
コンパイルメッセージ
warning: unused variable: `ok` --> src/main.rs:44:14 | 44 | let (ok, ng) = binary_search(-1, not_decided.len() as i32, |x: i32| { | ^^ help: if this is intentional, prefix it with an underscore: `_ok` | = note: `#[warn(unused_variables)]` on by default warning: function `read_vec` is never used --> src/main.rs:96:4 | 96 | fn read_vec<T: std::str::FromStr>() -> Vec<T> { | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[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 print_array<T: std::string::ToString>(array: &Vec<T>) { println!( "{}", array .iter() .map(|ref x| x.to_string()) .collect::<Vec<_>>() .join(" ") ); } fn query(a: &BTreeSet<usize>) -> i32 { let a = a.into_iter().map(|x| x + 1).collect::<Vec<_>>(); println!("? {}", a.len()); print_array(&a); read::<i32>() } fn main() { let n = read::<usize>(); let mut decided: BTreeSet<usize> = vec![0, 1].into_iter().collect::<BTreeSet<_>>(); let mut not_decided = (2..n).collect::<Vec<_>>(); loop { if query(&decided) == 1 { break; } let (ok, ng) = binary_search(-1, not_decided.len() as i32, |x: i32| { if x == decided.len() as i32 + 1 { return true; } if x == decided.len() as i32 { return false; } let mut query_numbers = not_decided .iter() .cloned() .take(x as usize + 1) .collect::<BTreeSet<_>>(); for &num in decided.iter() { query_numbers.insert(num); } let ret = query(&query_numbers) == 0; ret }); decided.insert(not_decided[ng as usize]); not_decided.remove(ng as usize); debug!(ng, decided); if not_decided.is_empty() { break; } } decided.remove(&0); let mut zero_needed = false; if query(&decided) == 0 { zero_needed = true; } decided.insert(0); decided.remove(&1); if query(&decided) == 0 { decided.insert(1); } if !zero_needed { decided.remove(&0); } let decided = decided.iter().map(|&x| x + 1).collect::<Vec<_>>(); println!("! {}", decided.len()); print_array(&decided); } 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() } fn binary_search<F>(lb: i32, ub: i32, criterion: F) -> (i32, i32) where F: Fn(i32) -> bool, { 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) }