結果

問題 No.2124 Guess the Permutation
ユーザー Ricky_ponRicky_pon
提出日時 2022-11-18 21:32:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 2,776 ms
コンパイル使用メモリ 176,344 KB
実行使用メモリ 24,588 KB
平均クエリ数 374.60
最終ジャッジ日時 2023-10-20 06:19:35
合計ジャッジ時間 4,040 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,588 KB
testcase_01 AC 24 ms
24,588 KB
testcase_02 AC 23 ms
24,588 KB
testcase_03 AC 25 ms
24,588 KB
testcase_04 AC 26 ms
24,588 KB
testcase_05 AC 28 ms
24,588 KB
testcase_06 AC 42 ms
24,588 KB
testcase_07 AC 56 ms
24,588 KB
testcase_08 AC 57 ms
24,588 KB
testcase_09 AC 55 ms
24,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

fn main() {
    let n = read_int();
    let mut p = vec![0; n];
    p[0] = n * (n + 1) / 2 - interact(2, n);
    for i in 1..=n - 2 {
        p[i] = interact(i, i + 1) - p[i - 1];
    }
    p[n - 1] = n * (n + 1) / 2 - p.iter().sum::<usize>();
    println!(
        "! {}",
        p.iter()
            .map(|&x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

fn interact(l: usize, r: usize) -> usize {
    println!("? {} {}", l, r);
    read_int()
}

fn read_int() -> usize {
    let mut buf = String::new();
    stdin().read_line(&mut buf).expect("input error!");
    buf.trim().parse().unwrap()
}
0