結果
問題 | No.934 Explosive energy drink |
ユーザー | fukafukatani |
提出日時 | 2019-11-29 23:29:27 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,164 bytes |
コンパイル時間 | 18,796 ms |
コンパイル使用メモリ | 405,736 KB |
実行使用メモリ | 31,832 KB |
平均クエリ数 | 469.25 |
最終ジャッジ日時 | 2024-07-16 18:52:14 |
合計ジャッジ時間 | 22,173 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
25,220 KB |
testcase_01 | AC | 27 ms
24,836 KB |
testcase_02 | AC | 23 ms
25,220 KB |
testcase_03 | AC | 29 ms
25,220 KB |
testcase_04 | RE | - |
testcase_05 | AC | 21 ms
24,832 KB |
testcase_06 | AC | 23 ms
24,580 KB |
testcase_07 | AC | 23 ms
24,964 KB |
testcase_08 | AC | 22 ms
24,964 KB |
testcase_09 | AC | 22 ms
24,580 KB |
testcase_10 | AC | 23 ms
24,964 KB |
testcase_11 | AC | 22 ms
24,580 KB |
testcase_12 | AC | 26 ms
24,836 KB |
testcase_13 | AC | 44 ms
25,220 KB |
testcase_14 | AC | 86 ms
24,836 KB |
testcase_15 | RE | - |
testcase_16 | AC | 24 ms
25,448 KB |
testcase_17 | AC | 28 ms
24,580 KB |
testcase_18 | AC | 115 ms
24,580 KB |
testcase_19 | AC | 29 ms
25,220 KB |
testcase_20 | AC | 156 ms
25,220 KB |
testcase_21 | AC | 35 ms
24,964 KB |
testcase_22 | AC | 66 ms
25,216 KB |
testcase_23 | AC | 43 ms
25,208 KB |
コンパイルメッセージ
warning: unused variable: `ng` --> src/main.rs:49:18 | 49 | let (ok, ng) = binary_search(0, not_decided.len(), |x| { | ^^ help: if this is intentional, prefix it with an underscore: `_ng` | = note: `#[warn(unused_variables)]` on by default warning: function `read_vec` is never used --> src/main.rs:108:4 | 108 | 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>, cache: &HashMap<BTreeSet<usize>, i32>) -> i32 { if cache.contains_key(a) { return cache[a]; } let a = a.into_iter().map(|x| x + 1).collect::<Vec<_>>(); println!("? {}", a.len()); print_array(&a); let ret = read::<i32>(); ret } 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<_>>(); let mut cache = HashMap::new(); loop { if query(&decided, &cache) == 1 { break; } let (ok, ng) = binary_search(0, not_decided.len(), |x| { if x == 0 { return true; } if x == not_decided.len() { return false; } let mut query_numbers = not_decided.iter().cloned().take(x).collect::<BTreeSet<_>>(); for &num in decided.iter() { query_numbers.insert(num); } let ret = query(&query_numbers, &cache); cache.insert(query_numbers, ret); ret == 0 }); decided.insert(not_decided[ok]); not_decided.remove(ok); debug!(ok, decided); if not_decided.is_empty() { break; } } let mut hojuu = false; if decided.len() == 2 { hojuu = true; decided.insert(2); } decided.remove(&0); let mut zero_needed = false; if query(&decided, &cache) == 0 { zero_needed = true; } decided.insert(0); decided.remove(&1); if query(&decided, &cache) == 0 { decided.insert(1); } if !zero_needed { decided.remove(&0); } if hojuu { decided.remove(&2); } 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: usize, ub: usize, mut criterion: F) -> (usize, usize) where F: FnMut(usize) -> 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) }