結果

問題 No.3347 Guess The Array
コンテスト
ユーザー akakimidori
提出日時 2025-11-13 23:05:22
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,165 bytes
コンパイル時間 13,523 ms
コンパイル使用メモリ 398,784 KB
実行使用メモリ 25,984 KB
平均クエリ数 3119.59
最終ジャッジ日時 2025-11-13 23:05:49
合計ジャッジ時間 26,113 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
 --> src/main.rs:2:5
  |
2 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: type alias `Map` is never used
 --> src/main.rs:4:6
  |
4 | type Map<K, V> = BTreeMap<K, V>;
  |      ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
 --> src/main.rs:5:6
  |
5 | type Set<T> = BTreeSet<T>;
  |      ^^^

warning: type alias `Deque` is never used
 --> src/main.rs:6:6
  |
6 | type Deque<T> = VecDeque<T>;
  |      ^^^^^

ソースコード

diff #

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

// bool が帰ってくる
// N=500
// Q=5000
// N log_2 N
// 厳しめ
// 個数を特定するのに2N程度使ってしまう
// ここからマージしていく?
// 足りるか微妙なラインだが

fn main() {
    use util::*;
    let n = read().parse::<usize>().unwrap();
    let mut cnt = 0;
    let mut query = |b: Vec<usize>| -> bool {
        cnt += 1;
        assert!(cnt <= 5000);
        use util::*;
        println!("? {} {}", b.len(), b.iter().join(" "));
        read() == "Yes"
    };
    let mut a = vec![];
    let mut rem = n;
    for i in 1..n {
        let mut b = vec![i];
        while b.len() <= rem && query(b.clone()) {
            b.push(i);
        }
        b.pop();
        rem -= b.len();
        a.push(b);
    }
    if rem > 0 {
        a.push(vec![n; rem]);
    }
    while a.len() > 1 {
        a.sort_by_key(|a| !a.len());
        let x = a.pop().unwrap();
        let y = a.pop().unwrap();
        let mut z = x.clone();
        let mut po = 0;
        for y in y {
            while po < z.len() {
                let mut t = z.clone();
                t.insert(po, y);
                if query(t) {
                    break;
                }
                po += 1;
            }
            z.insert(po, y);
            po += 1;
        }
        a.push(z);
    }
    println!("! {}", a[0].iter().join(" "));
}

fn read() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    String::from(s.trim())
}

mod util {
    pub trait Join {
        fn join(self, sep: &str) -> String;
    }

    impl<T, I> Join for I
    where
        I: Iterator<Item = T>,
        T: std::fmt::Display,
    {
        fn join(self, sep: &str) -> String {
            let mut s = String::new();
            use std::fmt::*;
            for (i, v) in self.enumerate() {
                if i > 0 {
                    write!(&mut s, "{}", sep).ok();
                }
                write!(&mut s, "{}", v).ok();
            }
            s
        }
    }
}
0