結果

問題 No.1959 Prefix MinMax
ユーザー akakimidoriakakimidori
提出日時 2022-05-27 22:48:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 5,268 ms
コンパイル使用メモリ 175,368 KB
実行使用メモリ 24,684 KB
平均クエリ数 26.72
最終ジャッジ日時 2023-10-20 21:23:12
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
24,672 KB
testcase_01 AC 25 ms
24,672 KB
testcase_02 AC 23 ms
24,672 KB
testcase_03 AC 23 ms
24,672 KB
testcase_04 AC 24 ms
24,672 KB
testcase_05 AC 25 ms
24,672 KB
testcase_06 AC 24 ms
24,672 KB
testcase_07 AC 34 ms
24,672 KB
testcase_08 AC 35 ms
24,672 KB
testcase_09 AC 35 ms
24,672 KB
testcase_10 AC 35 ms
24,672 KB
testcase_11 AC 34 ms
24,672 KB
testcase_12 AC 34 ms
24,672 KB
testcase_13 AC 35 ms
24,672 KB
testcase_14 AC 35 ms
24,672 KB
testcase_15 AC 35 ms
24,672 KB
testcase_16 AC 36 ms
24,672 KB
testcase_17 AC 35 ms
24,672 KB
testcase_18 AC 35 ms
24,672 KB
testcase_19 AC 35 ms
24,672 KB
testcase_20 AC 35 ms
24,672 KB
testcase_21 AC 36 ms
24,672 KB
testcase_22 AC 35 ms
24,672 KB
testcase_23 AC 35 ms
24,672 KB
testcase_24 AC 36 ms
24,672 KB
testcase_25 AC 35 ms
24,672 KB
testcase_26 AC 35 ms
24,672 KB
testcase_27 AC 35 ms
24,672 KB
testcase_28 AC 35 ms
24,672 KB
testcase_29 AC 35 ms
24,672 KB
testcase_30 AC 35 ms
24,672 KB
testcase_31 AC 35 ms
24,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:46:13
   |
46 |         let mut p = (1..=n).collect::<Vec<_>>();
   |             ----^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

diff #

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
        }
    }
}

fn read() -> Vec<usize> {
    let mut s = String::new();
    loop {
        std::io::stdin().read_line(&mut s).unwrap();
        let res = s
            .trim()
            .split_whitespace()
            .flat_map(|s| s.parse())
            .collect::<Vec<_>>();
        if res.len() > 0 {
            return res;
        }
    }
}

use util::*;

struct Oracle(Vec<usize>);

impl Oracle {
    fn new(n: usize) -> Self {
        let mut p = (1..=n).collect::<Vec<_>>();
        Self(p)
    }
    fn query(&self, a: &[u8]) -> Vec<usize> {
        assert!(a.len() + 1 == self.0.len() && a.iter().all(|a| *a <= 1));
        println!("? {}", a.iter().join(" "));
        read()
    }
    fn answer(&self, p: &[usize]) -> bool {
        println!("! {}", p.iter().join(" "));
        true
    }
}

fn run(n: usize) {
    let oracle = Oracle::new(n);
    let mut res = vec![];
    for k in 0..2 {
        let mut ask = vec![];
        for i in 0..(n - 1) {
            ask.push((i & 1 ^ k)as u8);
        }
        res.push(oracle.query(&ask));
    }
    let mut ans = vec![0; n];
    ans[0] = res[0][0];
    for i in 0..(n - 1) {
        for res in res.iter() {
            if res[i] != res[i + 1] {
                ans[i + 1] = res[i + 1];
                break;
            }
        }
    }
    assert!(oracle.answer(&ans), "Hack! {:?} {:?}", ans, oracle.0);
}

fn main() {
    let t = read()[0];
    for _ in 0..t {
        let n = read()[0];
        run(n);
    }
}
0