結果

問題 No.1306 Exactly 2 Digits
ユーザー akakimidoriakakimidori
提出日時 2020-12-03 01:41:12
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,949 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 162,372 KB
実行使用メモリ 24,528 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:47:38
合計ジャッジ時間 36,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,664 KB
testcase_01 AC 26 ms
23,436 KB
testcase_02 AC 25 ms
23,616 KB
testcase_03 AC 25 ms
24,024 KB
testcase_04 AC 26 ms
24,036 KB
testcase_05 AC 27 ms
24,324 KB
testcase_06 AC 26 ms
23,520 KB
testcase_07 AC 26 ms
24,360 KB
testcase_08 AC 26 ms
24,024 KB
testcase_09 AC 26 ms
24,024 KB
testcase_10 AC 26 ms
23,364 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 27 ms
23,364 KB
testcase_14 WA -
testcase_15 AC 26 ms
23,424 KB
testcase_16 AC 27 ms
23,364 KB
testcase_17 AC 27 ms
24,084 KB
testcase_18 WA -
testcase_19 AC 26 ms
23,424 KB
testcase_20 WA -
testcase_21 AC 26 ms
23,640 KB
testcase_22 AC 26 ms
23,880 KB
testcase_23 AC 27 ms
24,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 26 ms
23,640 KB
testcase_29 AC 26 ms
23,664 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 27 ms
24,072 KB
testcase_34 WA -
testcase_35 AC 28 ms
23,436 KB
testcase_36 AC 27 ms
23,520 KB
testcase_37 AC 30 ms
24,000 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 27 ms
23,424 KB
testcase_43 AC 28 ms
23,412 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 34 ms
23,880 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 39 ms
24,036 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 135 ms
23,628 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 AC 315 ms
24,024 KB
testcase_98 AC 274 ms
23,568 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 AC 292 ms
24,252 KB
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 WA -
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 AC 337 ms
24,048 KB
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: the item `Write` is imported redundantly
   --> Main.rs:18:13
    |
18  |         use std::io::Write;
    |             ^^^^^^^^^^^^^^
...
108 |     use std::io::Write;
    |         -------------- the item `Write` is already imported here
    |
    = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn read() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn run() {
    let n = read()[0] as usize;
    let len = n * n - n;
    let mut cnt = 0;
    let mut query = |x: usize, y: usize| -> (i32, i32) {
        assert!(x != y);
        assert!(x < len);
        assert!(y < len);
        assert!(cnt < n * (n - 1) / 2 * 3);
        cnt += 1;
        println!("? {} {}", x + 1, y + 1);
        use std::io::Write;
        std::io::stdout().flush().ok();
        let a = read();
        (a[0], a[1])
    };
    let m = n as i32;
    let hash = |x: i32, y: i32| -> (i32, i32) {
        assert!(m <= x && x < m * m);
        assert!(m <= y && y < m * m);
        let mut p = x / m - y / m;
        let mut q = x % m - y % m;
        if p > q {
            std::mem::swap(&mut p, &mut q);
        }
        (p, q)
    };
    let mut memo = vec![(0, 0); len];
    let mut used = vec![];
    for i in 1..len {
        memo[i] = query(0, i);
        used.push((0, i, memo[i]));
    }
    let mut key = memo.clone();
    key.remove(0);
    key.sort();
    let mut ans = vec![0; len];
    for i in m..(m * m) {
        let mut a = vec![];
        for j in m..(m * m) {
            if i == j {
                continue;
            }
            a.push(hash(i, j));
        }
        a.sort();
        if a == key {
            assert!(ans[0] == 0);
            ans[0] = i;
        }
    }
    let mut map = std::collections::BTreeMap::new();
    for i in 1..(n * n - n) {
        map.entry(memo[i]).or_insert(vec![]).push(i);
    }
    for i in 1..len {
        if ans[i] != 0 {
            continue;
        }
        let index = map.get(&memo[i]).unwrap();
        assert!(index[0] == i);
        assert!(index.len() <= 2);
        if index.len() == 1 {
            for v in m..(m * m) {
                if v == ans[0] {
                    continue;
                }
                if hash(ans[0], v) == memo[i] {
                    ans[i] = v;
                    break;
                }
            }
        } else {
            let mut cond = vec![];
            for v in m..(m * m) {
                if v == ans[0] {
                    continue;
                }
                if hash(ans[0], v) == memo[i] {
                    cond.push(v);
                }
            }
            assert!(cond.len() == 2);
            let j = index[1];
            let p = query(i, j);
            used.push((i, j, p));
            let (x, y) = (cond[0], cond[1]);
            if p == hash(x, y) {
                ans[i] = x;
                ans[j] = y;
            } else {
                ans[i] = y;
                ans[j] = x;
            }
        }
    }
    print!("!");
    for a in ans {
        print!(" {}", a);
    }
    println!();
    use std::io::Write;
    std::io::stdout().flush().ok();
}

fn main() {
    run();
}
0