結果

問題 No.2085 Directed Complete Graph
ユーザー akakimidoriakakimidori
提出日時 2022-09-26 22:50:06
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,525 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 151,164 KB
実行使用メモリ 24,420 KB
平均クエリ数 2533.29
最終ジャッジ日時 2023-08-24 03:14:41
合計ジャッジ時間 4,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,420 KB
testcase_01 AC 23 ms
24,072 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 79 ms
23,880 KB
testcase_06 AC 83 ms
23,520 KB
testcase_07 AC 147 ms
23,448 KB
testcase_08 AC 112 ms
23,592 KB
testcase_09 AC 142 ms
23,448 KB
testcase_10 AC 148 ms
23,532 KB
testcase_11 AC 149 ms
24,036 KB
testcase_12 AC 148 ms
24,372 KB
testcase_13 AC 146 ms
23,640 KB
testcase_14 AC 149 ms
24,072 KB
testcase_15 AC 22 ms
23,496 KB
testcase_16 AC 22 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let n = read();
    let mut p = (1..=n).collect::<Vec<_>>();
    shuffle(&mut p);
    p.sort_unstable_by(|a, b| {
        println!("? {} {}", *a, *b);
        let res = read();
        use std::cmp::Ordering::*;
        if res == 1 {
            Less
        } else {
            Greater
        }
    });
    println!("!");
    println!("{}", n - 1);
    use util::*;
    println!("{}", p.iter().join(" "));
}

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

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 rand_memory() -> usize {
    Box::into_raw(Box::new("I hope this is a random number")) as usize
}

fn rand() -> usize {
    static mut X: usize = 0;
    unsafe {
        if X == 0 {
            X = rand_memory();
        }
        X ^= X << 13;
        X ^= X >> 17;
        X ^= X << 5;
        X
    }
}

fn shuffle<T>(a: &mut [T]) {
    for i in 1..a.len() {
        let p = rand() % (i + 1);
        a.swap(i, p);
    }
}
0