結果

問題 No.1306 Exactly 2 Digits
ユーザー akakimidoriakakimidori
提出日時 2020-12-03 02:56:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 3,230 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 164,264 KB
実行使用メモリ 24,408 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 08:00:38
合計ジャッジ時間 24,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,300 KB
testcase_01 AC 24 ms
23,412 KB
testcase_02 AC 24 ms
23,880 KB
testcase_03 AC 24 ms
23,340 KB
testcase_04 AC 24 ms
23,304 KB
testcase_05 AC 24 ms
23,964 KB
testcase_06 AC 24 ms
23,568 KB
testcase_07 AC 24 ms
23,304 KB
testcase_08 AC 24 ms
23,592 KB
testcase_09 AC 26 ms
23,568 KB
testcase_10 AC 24 ms
24,288 KB
testcase_11 AC 24 ms
24,096 KB
testcase_12 AC 24 ms
24,276 KB
testcase_13 AC 25 ms
23,688 KB
testcase_14 AC 24 ms
23,292 KB
testcase_15 AC 25 ms
23,568 KB
testcase_16 AC 23 ms
24,060 KB
testcase_17 AC 24 ms
24,264 KB
testcase_18 AC 25 ms
23,304 KB
testcase_19 AC 25 ms
23,292 KB
testcase_20 AC 24 ms
23,568 KB
testcase_21 AC 25 ms
23,436 KB
testcase_22 AC 24 ms
23,748 KB
testcase_23 AC 25 ms
23,868 KB
testcase_24 AC 25 ms
23,448 KB
testcase_25 AC 24 ms
23,460 KB
testcase_26 AC 25 ms
23,940 KB
testcase_27 AC 24 ms
24,084 KB
testcase_28 AC 23 ms
23,640 KB
testcase_29 AC 24 ms
24,276 KB
testcase_30 AC 24 ms
23,688 KB
testcase_31 AC 25 ms
23,592 KB
testcase_32 AC 25 ms
23,580 KB
testcase_33 AC 24 ms
23,448 KB
testcase_34 AC 25 ms
23,928 KB
testcase_35 AC 24 ms
23,580 KB
testcase_36 AC 24 ms
24,288 KB
testcase_37 AC 25 ms
24,300 KB
testcase_38 AC 25 ms
23,556 KB
testcase_39 AC 25 ms
23,328 KB
testcase_40 AC 26 ms
23,748 KB
testcase_41 AC 25 ms
24,288 KB
testcase_42 AC 25 ms
23,820 KB
testcase_43 AC 25 ms
24,288 KB
testcase_44 AC 27 ms
23,436 KB
testcase_45 AC 26 ms
23,928 KB
testcase_46 AC 28 ms
23,448 KB
testcase_47 AC 28 ms
24,252 KB
testcase_48 AC 30 ms
24,276 KB
testcase_49 AC 31 ms
23,700 KB
testcase_50 AC 31 ms
23,736 KB
testcase_51 AC 33 ms
23,448 KB
testcase_52 AC 35 ms
23,412 KB
testcase_53 AC 38 ms
23,460 KB
testcase_54 AC 36 ms
24,288 KB
testcase_55 AC 42 ms
23,868 KB
testcase_56 AC 44 ms
23,556 KB
testcase_57 AC 46 ms
24,408 KB
testcase_58 AC 49 ms
24,372 KB
testcase_59 AC 50 ms
23,316 KB
testcase_60 AC 58 ms
24,288 KB
testcase_61 AC 63 ms
24,288 KB
testcase_62 AC 66 ms
24,360 KB
testcase_63 AC 70 ms
23,292 KB
testcase_64 AC 72 ms
23,544 KB
testcase_65 AC 77 ms
23,448 KB
testcase_66 AC 84 ms
23,916 KB
testcase_67 AC 88 ms
23,448 KB
testcase_68 AC 90 ms
23,928 KB
testcase_69 AC 99 ms
23,304 KB
testcase_70 AC 109 ms
23,412 KB
testcase_71 AC 117 ms
24,288 KB
testcase_72 AC 122 ms
23,568 KB
testcase_73 AC 128 ms
24,288 KB
testcase_74 AC 150 ms
23,328 KB
testcase_75 AC 150 ms
23,748 KB
testcase_76 AC 169 ms
24,288 KB
testcase_77 AC 185 ms
23,976 KB
testcase_78 AC 203 ms
24,300 KB
testcase_79 AC 220 ms
24,288 KB
testcase_80 AC 234 ms
23,868 KB
testcase_81 AC 220 ms
23,916 KB
testcase_82 AC 261 ms
23,676 KB
testcase_83 AC 287 ms
23,544 KB
testcase_84 AC 303 ms
23,580 KB
testcase_85 AC 343 ms
24,144 KB
testcase_86 AC 280 ms
24,300 KB
testcase_87 AC 308 ms
24,288 KB
testcase_88 AC 354 ms
23,652 KB
testcase_89 AC 290 ms
24,180 KB
testcase_90 AC 315 ms
23,292 KB
testcase_91 AC 277 ms
23,928 KB
testcase_92 AC 295 ms
24,084 KB
testcase_93 AC 301 ms
23,424 KB
testcase_94 AC 264 ms
23,292 KB
testcase_95 AC 284 ms
24,288 KB
testcase_96 AC 258 ms
23,448 KB
testcase_97 AC 292 ms
23,652 KB
testcase_98 AC 259 ms
24,300 KB
testcase_99 AC 273 ms
23,316 KB
testcase_100 AC 276 ms
23,580 KB
testcase_101 AC 303 ms
23,448 KB
testcase_102 AC 260 ms
23,916 KB
testcase_103 AC 267 ms
23,748 KB
testcase_104 AC 287 ms
23,556 KB
testcase_105 AC 320 ms
24,288 KB
testcase_106 AC 270 ms
24,300 KB
testcase_107 AC 321 ms
23,928 KB
testcase_108 AC 313 ms
23,580 KB
testcase_109 AC 345 ms
23,448 KB
testcase_110 AC 277 ms
24,060 KB
testcase_111 AC 317 ms
23,460 KB
testcase_112 AC 257 ms
23,676 KB
testcase_113 AC 345 ms
23,580 KB
testcase_114 AC 326 ms
23,568 KB
testcase_115 AC 301 ms
24,276 KB
testcase_116 AC 350 ms
23,412 KB
testcase_117 AC 303 ms
23,328 KB
testcase_118 AC 337 ms
23,748 KB
testcase_119 AC 317 ms
23,328 KB
testcase_120 AC 270 ms
23,412 KB
testcase_121 AC 298 ms
23,292 KB
testcase_122 AC 297 ms
23,664 KB
権限があれば一括ダウンロードができます

ソースコード

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);
        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.sort();
    let mut ans = vec![0; len];
    for i in m..(m * m) {
        let mut a = vec![];
        for j in m..(m * m) {
            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..len {
        map.entry(memo[i]).or_insert(vec![]).push(i);
    }
    for (&memo, index) in map.iter().filter(|p| p.1.len() == 1) {
        let i = index[0];
        for v in m..(m * m) {
            if v == ans[0] {
                continue;
            }
            if hash(ans[0], v) == memo {
                ans[i] = v;
                break;
            }
        }
    }
    for (&memo, index) in map.iter().filter(|p| p.1.len() == 2) {
        let (i, j) = (index[0], index[1]);
        let mut cond = vec![];
        for v in m..(m * m) {
            if v == ans[0] {
                continue;
            }
            if hash(ans[0], v) == memo {
                cond.push(v);
            }
        }
        assert!(cond.len() == 2);
        let (a, b) = hash(cond[0], cond[1]);
        if a.abs() != b.abs() {
            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;
            }
        } else {
            let q = ans.iter().position(|p| {
                *p > 0 && hash(*p, cond[0]) != hash(*p, cond[1])
            }).unwrap();
            let (x, y) = (cond[0], cond[1]);
            if hash(ans[q], cond[0]) == query(q, i) {
                ans[i] = x;
                ans[j] = y;
            } else {
                ans[i] = y;
                ans[j] = x;
            }
        }
    }
    {
        let mut p = ans.clone();
        p.sort();
        p.dedup();
        assert!(p.len() == len);
        assert!(p[0] == m);
    }
    print!("!");
    for a in ans {
        print!(" {}", a);
    }
    println!();
}

fn main() {
    run();
}
0