結果
| 問題 |
No.2124 Guess the Permutation
|
| コンテスト | |
| ユーザー |
Ricky_pon
|
| 提出日時 | 2022-11-18 21:32:50 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 655 bytes |
| コンパイル時間 | 13,340 ms |
| コンパイル使用メモリ | 377,532 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 374.60 |
| 最終ジャッジ日時 | 2024-09-20 01:57:19 |
| 合計ジャッジ時間 | 14,015 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
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()
}
Ricky_pon