結果

問題 No.1306 Exactly 2 Digits
ユーザー akakimidoriakakimidori
提出日時 2020-12-03 02:56:33
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 3,230 bytes
コンパイル時間 17,807 ms
コンパイル使用メモリ 389,196 KB
実行使用メモリ 25,476 KB
平均クエリ数 1236.78
最終ジャッジ日時 2024-07-17 08:22:59
合計ジャッジ時間 37,336 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,580 KB
testcase_01 AC 22 ms
24,964 KB
testcase_02 AC 22 ms
24,964 KB
testcase_03 AC 23 ms
24,836 KB
testcase_04 AC 23 ms
24,836 KB
testcase_05 AC 23 ms
25,220 KB
testcase_06 AC 22 ms
24,836 KB
testcase_07 AC 23 ms
24,836 KB
testcase_08 AC 22 ms
25,092 KB
testcase_09 AC 22 ms
24,964 KB
testcase_10 AC 23 ms
24,836 KB
testcase_11 AC 22 ms
24,836 KB
testcase_12 AC 23 ms
24,836 KB
testcase_13 AC 23 ms
25,220 KB
testcase_14 AC 22 ms
25,204 KB
testcase_15 AC 22 ms
24,836 KB
testcase_16 AC 22 ms
24,964 KB
testcase_17 AC 23 ms
25,460 KB
testcase_18 AC 23 ms
24,836 KB
testcase_19 AC 22 ms
24,580 KB
testcase_20 AC 22 ms
25,220 KB
testcase_21 AC 23 ms
25,220 KB
testcase_22 AC 22 ms
24,964 KB
testcase_23 AC 23 ms
24,836 KB
testcase_24 AC 22 ms
24,836 KB
testcase_25 AC 22 ms
24,452 KB
testcase_26 AC 22 ms
24,836 KB
testcase_27 AC 23 ms
24,964 KB
testcase_28 AC 22 ms
24,580 KB
testcase_29 AC 23 ms
24,580 KB
testcase_30 AC 22 ms
25,220 KB
testcase_31 AC 23 ms
24,836 KB
testcase_32 AC 23 ms
25,220 KB
testcase_33 AC 22 ms
24,836 KB
testcase_34 AC 24 ms
25,220 KB
testcase_35 AC 23 ms
25,220 KB
testcase_36 AC 24 ms
25,220 KB
testcase_37 AC 23 ms
24,836 KB
testcase_38 AC 23 ms
24,836 KB
testcase_39 AC 23 ms
24,836 KB
testcase_40 AC 23 ms
24,836 KB
testcase_41 AC 23 ms
25,220 KB
testcase_42 AC 23 ms
24,836 KB
testcase_43 AC 24 ms
25,076 KB
testcase_44 AC 24 ms
25,220 KB
testcase_45 AC 25 ms
24,836 KB
testcase_46 AC 26 ms
24,580 KB
testcase_47 AC 27 ms
24,836 KB
testcase_48 AC 28 ms
24,580 KB
testcase_49 AC 29 ms
24,580 KB
testcase_50 AC 30 ms
25,220 KB
testcase_51 AC 32 ms
25,220 KB
testcase_52 AC 33 ms
24,964 KB
testcase_53 AC 37 ms
25,092 KB
testcase_54 AC 35 ms
24,580 KB
testcase_55 AC 39 ms
24,580 KB
testcase_56 AC 41 ms
25,220 KB
testcase_57 AC 43 ms
25,220 KB
testcase_58 AC 47 ms
25,476 KB
testcase_59 AC 47 ms
25,220 KB
testcase_60 AC 56 ms
24,964 KB
testcase_61 AC 61 ms
24,964 KB
testcase_62 AC 63 ms
24,836 KB
testcase_63 AC 70 ms
24,836 KB
testcase_64 AC 72 ms
24,836 KB
testcase_65 AC 76 ms
25,220 KB
testcase_66 AC 85 ms
24,452 KB
testcase_67 AC 91 ms
25,220 KB
testcase_68 AC 94 ms
25,220 KB
testcase_69 AC 102 ms
24,580 KB
testcase_70 AC 110 ms
25,220 KB
testcase_71 AC 119 ms
24,836 KB
testcase_72 AC 123 ms
25,220 KB
testcase_73 AC 127 ms
24,836 KB
testcase_74 AC 151 ms
25,476 KB
testcase_75 AC 152 ms
25,220 KB
testcase_76 AC 174 ms
24,580 KB
testcase_77 AC 189 ms
24,836 KB
testcase_78 AC 208 ms
24,836 KB
testcase_79 AC 229 ms
24,836 KB
testcase_80 AC 242 ms
24,836 KB
testcase_81 AC 232 ms
25,220 KB
testcase_82 AC 273 ms
25,220 KB
testcase_83 AC 303 ms
25,064 KB
testcase_84 AC 315 ms
24,824 KB
testcase_85 AC 358 ms
25,220 KB
testcase_86 AC 293 ms
24,580 KB
testcase_87 AC 318 ms
24,836 KB
testcase_88 AC 367 ms
25,208 KB
testcase_89 AC 302 ms
24,836 KB
testcase_90 AC 325 ms
25,220 KB
testcase_91 AC 285 ms
24,580 KB
testcase_92 AC 303 ms
24,964 KB
testcase_93 AC 314 ms
24,836 KB
testcase_94 AC 274 ms
25,076 KB
testcase_95 AC 295 ms
24,580 KB
testcase_96 AC 269 ms
24,580 KB
testcase_97 AC 303 ms
24,452 KB
testcase_98 AC 268 ms
24,580 KB
testcase_99 AC 284 ms
25,092 KB
testcase_100 AC 291 ms
24,836 KB
testcase_101 AC 315 ms
25,220 KB
testcase_102 AC 271 ms
24,836 KB
testcase_103 AC 277 ms
24,964 KB
testcase_104 AC 297 ms
25,220 KB
testcase_105 AC 331 ms
24,836 KB
testcase_106 AC 288 ms
25,220 KB
testcase_107 AC 333 ms
25,220 KB
testcase_108 AC 326 ms
25,220 KB
testcase_109 AC 354 ms
24,824 KB
testcase_110 AC 289 ms
25,220 KB
testcase_111 AC 330 ms
25,220 KB
testcase_112 AC 269 ms
24,836 KB
testcase_113 AC 361 ms
24,964 KB
testcase_114 AC 337 ms
24,836 KB
testcase_115 AC 315 ms
25,220 KB
testcase_116 AC 360 ms
25,460 KB
testcase_117 AC 315 ms
24,836 KB
testcase_118 AC 346 ms
24,836 KB
testcase_119 AC 328 ms
24,824 KB
testcase_120 AC 287 ms
24,964 KB
testcase_121 AC 308 ms
24,836 KB
testcase_122 AC 309 ms
24,964 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