結果
問題 | No.934 Explosive energy drink |
ユーザー | fukafukatani |
提出日時 | 2019-11-29 22:31:29 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,500 bytes |
コンパイル時間 | 28,444 ms |
コンパイル使用メモリ | 382,472 KB |
実行使用メモリ | 25,460 KB |
平均クエリ数 | 1.00 |
最終ジャッジ日時 | 2024-07-16 18:40:21 |
合計ジャッジ時間 | 23,665 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
コンパイルメッセージ
warning: function `read_vec` is never used --> src/main.rs:81:4 | 81 | 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<_>>(); print!("? "); print_array(&a); read::<i32>() } fn main() { let n = read::<usize>(); let mut decided: Vec<usize> = vec![]; let mut not_decided = (0..n).collect::<Vec<_>>(); // let criterion = loop { let (ok, _) = binary_search(-1, not_decided.len() as i32 + 1, |x: i32| { if x == -1 { return true; } if x == decided.len() as i32 + 1 { 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); } query(&query_numbers) == 0 }); if ok == -1 { break; } decided.push(not_decided[ok as usize]); not_decided.remove(ok as usize); if not_decided.is_empty() { break; } } decided.sort(); 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) }