結果

問題 No.934 Explosive energy drink
ユーザー fukafukatanifukafukatani
提出日時 2019-11-29 23:18:53
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 2,923 bytes
コンパイル時間 15,330 ms
コンパイル使用メモリ 404,120 KB
実行使用メモリ 25,604 KB
平均クエリ数 504.50
最終ジャッジ日時 2024-07-16 18:49:55
合計ジャッジ時間 15,983 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
24,836 KB
testcase_01 AC 25 ms
25,220 KB
testcase_02 AC 19 ms
24,836 KB
testcase_03 AC 27 ms
24,452 KB
testcase_04 RE -
testcase_05 AC 21 ms
24,836 KB
testcase_06 AC 21 ms
24,580 KB
testcase_07 AC 19 ms
24,580 KB
testcase_08 AC 20 ms
24,580 KB
testcase_09 AC 19 ms
25,092 KB
testcase_10 AC 20 ms
25,220 KB
testcase_11 AC 21 ms
24,580 KB
testcase_12 AC 26 ms
25,220 KB
testcase_13 AC 41 ms
24,836 KB
testcase_14 AC 74 ms
24,836 KB
testcase_15 RE -
testcase_16 AC 21 ms
25,220 KB
testcase_17 AC 26 ms
24,836 KB
testcase_18 AC 113 ms
24,836 KB
testcase_19 AC 24 ms
24,580 KB
testcase_20 AC 139 ms
25,092 KB
testcase_21 AC 33 ms
24,836 KB
testcase_22 AC 57 ms
25,220 KB
testcase_23 AC 39 ms
25,208 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `ng`
  --> src/main.rs:44:18
   |
44 |         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:102:4
    |
102 | fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    |    ^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

ソースコード

diff #

#![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(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) == 0;
            ret
        });
        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) == 0 {
        zero_needed = true;
    }
    decided.insert(0);

    decided.remove(&1);
    if query(&decided) == 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, criterion: F) -> (usize, usize)
where
    F: Fn(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)
}
0