結果

問題 No.1306 Exactly 2 Digits
ユーザー akakimidoriakakimidori
提出日時 2020-12-03 00:52:34
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,798 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 160,576 KB
実行使用メモリ 24,504 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 07:30:07
合計ジャッジ時間 37,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
23,640 KB
testcase_01 AC 26 ms
23,556 KB
testcase_02 AC 26 ms
23,352 KB
testcase_03 AC 26 ms
24,336 KB
testcase_04 AC 26 ms
23,400 KB
testcase_05 AC 25 ms
23,376 KB
testcase_06 AC 26 ms
24,348 KB
testcase_07 AC 25 ms
23,820 KB
testcase_08 AC 25 ms
23,820 KB
testcase_09 AC 26 ms
23,436 KB
testcase_10 AC 26 ms
23,652 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 27 ms
23,448 KB
testcase_14 WA -
testcase_15 AC 26 ms
23,508 KB
testcase_16 AC 26 ms
23,448 KB
testcase_17 AC 27 ms
23,664 KB
testcase_18 WA -
testcase_19 AC 26 ms
23,568 KB
testcase_20 WA -
testcase_21 AC 26 ms
23,520 KB
testcase_22 AC 26 ms
24,336 KB
testcase_23 AC 27 ms
23,508 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 26 ms
24,288 KB
testcase_29 AC 26 ms
23,448 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 27 ms
24,324 KB
testcase_34 WA -
testcase_35 AC 27 ms
23,664 KB
testcase_36 AC 26 ms
23,832 KB
testcase_37 AC 27 ms
24,336 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 26 ms
24,036 KB
testcase_43 AC 27 ms
23,844 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 33 ms
24,084 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 39 ms
24,360 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 137 ms
23,448 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 309 ms
24,360 KB
testcase_98 AC 273 ms
24,348 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 293 ms
24,036 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 335 ms
23,412 KB
testcase_120 WA -
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます

ソースコード

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 mut cnt = 0;
    let mut query = |x: usize, y: usize| -> (i32, i32) {
        assert!(x != y);
        assert!(x < n * n - n);
        assert!(y < n * n - n);
        assert!(cnt < n * (n - 1) / 2 * 3);
        cnt += 1;
        println!("? {} {}", x + 1, y + 1);
        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); n * n - n];
    for i in 1..(n * n - n) {
        memo[i] = query(0, i);
    }
    let mut key = memo.clone();
    key.remove(0);
    key.sort();
    let mut ans = vec![0; n * n - n];
    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..(n * n - n) {
        if ans[i] != 0 {
            continue;
        }
        let index = map.get(&memo[i]).unwrap();
        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);
                }
            }
            if query(index[0], index[1]) == hash(cond[0], cond[1]) {
                ans[index[0]] = cond[0];
                ans[index[1]] = cond[1];
            } else {
                ans[index[0]] = cond[1];
                ans[index[1]] = cond[0];
            }
        }
    }
    assert!(ans.iter().all(|a| m <= *a && *a < m * m));
    let mut p = ans.clone();
    p.sort();
    p.dedup();
    assert!(p.len() == n * n - n);
    print!("!");
    for a in ans {
        print!(" {}", a);
    }
    println!();
}

fn main() {
    run();
}
0