結果

問題 No.1306 Exactly 2 Digits
ユーザー ziitaziita
提出日時 2021-02-25 02:07:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 7,120 bytes
コンパイル時間 5,100 ms
コンパイル使用メモリ 157,468 KB
実行使用メモリ 24,396 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-24 09:50:56
合計ジャッジ時間 23,185 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,700 KB
testcase_01 AC 25 ms
24,372 KB
testcase_02 AC 25 ms
23,352 KB
testcase_03 AC 25 ms
23,508 KB
testcase_04 AC 25 ms
24,336 KB
testcase_05 AC 25 ms
23,796 KB
testcase_06 AC 24 ms
24,324 KB
testcase_07 AC 25 ms
23,664 KB
testcase_08 AC 24 ms
24,372 KB
testcase_09 AC 25 ms
23,712 KB
testcase_10 AC 25 ms
24,000 KB
testcase_11 AC 24 ms
23,628 KB
testcase_12 AC 24 ms
23,640 KB
testcase_13 AC 25 ms
23,580 KB
testcase_14 AC 25 ms
24,348 KB
testcase_15 AC 25 ms
24,372 KB
testcase_16 AC 25 ms
23,616 KB
testcase_17 AC 26 ms
24,372 KB
testcase_18 AC 25 ms
23,376 KB
testcase_19 AC 25 ms
24,000 KB
testcase_20 AC 25 ms
24,192 KB
testcase_21 AC 25 ms
23,508 KB
testcase_22 AC 24 ms
23,784 KB
testcase_23 AC 25 ms
23,352 KB
testcase_24 AC 26 ms
23,460 KB
testcase_25 AC 25 ms
23,520 KB
testcase_26 AC 26 ms
23,604 KB
testcase_27 AC 26 ms
23,628 KB
testcase_28 AC 25 ms
23,448 KB
testcase_29 AC 25 ms
23,964 KB
testcase_30 AC 26 ms
23,436 KB
testcase_31 AC 25 ms
23,592 KB
testcase_32 AC 26 ms
24,204 KB
testcase_33 AC 26 ms
23,352 KB
testcase_34 AC 25 ms
24,324 KB
testcase_35 AC 26 ms
23,784 KB
testcase_36 AC 26 ms
23,364 KB
testcase_37 AC 26 ms
24,372 KB
testcase_38 AC 26 ms
23,580 KB
testcase_39 AC 26 ms
23,988 KB
testcase_40 AC 26 ms
24,360 KB
testcase_41 AC 26 ms
24,012 KB
testcase_42 AC 26 ms
23,580 KB
testcase_43 AC 27 ms
24,024 KB
testcase_44 AC 28 ms
23,604 KB
testcase_45 AC 27 ms
23,628 KB
testcase_46 AC 28 ms
23,496 KB
testcase_47 AC 30 ms
23,988 KB
testcase_48 AC 32 ms
23,448 KB
testcase_49 AC 32 ms
23,640 KB
testcase_50 AC 33 ms
24,000 KB
testcase_51 AC 34 ms
23,652 KB
testcase_52 AC 36 ms
23,676 KB
testcase_53 AC 39 ms
23,880 KB
testcase_54 AC 38 ms
23,688 KB
testcase_55 AC 42 ms
23,604 KB
testcase_56 AC 44 ms
23,700 KB
testcase_57 AC 47 ms
24,072 KB
testcase_58 AC 49 ms
23,628 KB
testcase_59 AC 50 ms
23,340 KB
testcase_60 AC 58 ms
24,000 KB
testcase_61 AC 64 ms
24,060 KB
testcase_62 AC 66 ms
23,616 KB
testcase_63 AC 70 ms
23,352 KB
testcase_64 AC 71 ms
24,096 KB
testcase_65 AC 76 ms
24,000 KB
testcase_66 AC 85 ms
23,844 KB
testcase_67 AC 90 ms
23,592 KB
testcase_68 AC 93 ms
23,676 KB
testcase_69 AC 100 ms
24,012 KB
testcase_70 AC 102 ms
24,336 KB
testcase_71 AC 112 ms
23,700 KB
testcase_72 AC 118 ms
23,976 KB
testcase_73 AC 124 ms
23,388 KB
testcase_74 AC 141 ms
24,108 KB
testcase_75 AC 144 ms
23,352 KB
testcase_76 AC 161 ms
23,364 KB
testcase_77 AC 176 ms
23,688 KB
testcase_78 AC 187 ms
23,640 KB
testcase_79 AC 205 ms
23,412 KB
testcase_80 AC 216 ms
23,784 KB
testcase_81 AC 205 ms
23,400 KB
testcase_82 AC 237 ms
23,568 KB
testcase_83 AC 264 ms
23,580 KB
testcase_84 AC 272 ms
23,400 KB
testcase_85 AC 307 ms
23,988 KB
testcase_86 AC 258 ms
23,688 KB
testcase_87 AC 276 ms
24,096 KB
testcase_88 AC 315 ms
23,580 KB
testcase_89 AC 264 ms
24,372 KB
testcase_90 AC 279 ms
23,868 KB
testcase_91 AC 253 ms
24,084 KB
testcase_92 AC 265 ms
24,000 KB
testcase_93 AC 272 ms
24,396 KB
testcase_94 AC 242 ms
23,652 KB
testcase_95 AC 259 ms
24,360 KB
testcase_96 AC 238 ms
24,012 KB
testcase_97 AC 263 ms
23,988 KB
testcase_98 AC 236 ms
23,604 KB
testcase_99 AC 252 ms
23,376 KB
testcase_100 AC 253 ms
23,784 KB
testcase_101 AC 273 ms
23,676 KB
testcase_102 AC 240 ms
23,448 KB
testcase_103 AC 248 ms
23,412 KB
testcase_104 AC 258 ms
23,640 KB
testcase_105 AC 286 ms
23,640 KB
testcase_106 AC 248 ms
24,372 KB
testcase_107 AC 291 ms
23,784 KB
testcase_108 AC 279 ms
23,988 KB
testcase_109 AC 300 ms
24,024 KB
testcase_110 AC 252 ms
24,312 KB
testcase_111 AC 281 ms
23,640 KB
testcase_112 AC 236 ms
23,700 KB
testcase_113 AC 304 ms
23,352 KB
testcase_114 AC 292 ms
24,000 KB
testcase_115 AC 274 ms
23,448 KB
testcase_116 AC 311 ms
24,000 KB
testcase_117 AC 277 ms
24,000 KB
testcase_118 AC 297 ms
24,396 KB
testcase_119 AC 282 ms
24,372 KB
testcase_120 AC 248 ms
23,628 KB
testcase_121 AC 268 ms
23,412 KB
testcase_122 AC 266 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254 より

macro_rules! eprint {
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = write!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! eprintln {
    () => { eprintln!(""); };
    ($($t:tt)*) => {{
        use ::std::io::Write;
        let _ = writeln!(::std::io::stderr(), $($t)*);
    }};
}
macro_rules! dbg {
    ($v:expr) => {{
        let val = $v;
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
        val
    }}
}

macro_rules! mat {
    ($($e:expr),*) => { Vec::from(vec![$($e),*]) };
    ($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
    ($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
    ($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
    ($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
        $a$([$i])*.$f($($t),*)
    };
    ($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
        let t = $e;
        ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
    } };
}

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
    ($($t:tt),*; $n:expr) => {{
        let stdin = ::std::io::stdin();
        let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
            let line = line.unwrap();
            let mut it = line.split_whitespace();
            _read!(it; $($t),*)
        }).collect::<Vec<_>>();
        ret
    }};
    ($($t:tt),*) => {{
        let line = readln();
        let mut it = line.split_whitespace();
        _read!(it; $($t),*)
    }};
}

macro_rules! _read {
    ($it:ident; [char]) => {
        _read!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        Vec::from(_read!($it; String).into_bytes())
    };
    ($it:ident; usize1) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_read!($it; $t)),*)
    };
}


pub fn main() {
    let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 998244353;
// const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/100;
// const INF: usize = std::usize::MAX;
// const INF: i128 = std::i128::MAX/100;

fn solve() {
    let n = read!(usize);
    let total = n*n - n;
    let mut count = vec![vec![0;2*n+1];2*n+1];
    let mut list = vec![vec![vec![];2*n+1];2*n+1];
    for i in 2..=total {
        let (p,q) = query(1,i);
        let a = (n as i64 + p) as usize;
        let b = (n as i64 + q) as usize;
        count[a][b] += 1;
        list[a][b].push(i-1);
    }
    let mut ans = vec![(0,0);total];
    for a in 1..=n-1 {
        for b in 0..=n-1 {
            let mut c = vec![vec![0;2*n+1];2*n+1];
            for x in 1..=n-1 {
                for y in 0..=n-1 {
                    if (a,b)==(x,y) {
                        continue;
                    }
                    let p = n + a - x;
                    let q = n + b - y;
                    c[min(p,q)][max(p,q)] += 1;
                }
            }
            let mut flag = true;
            for x in 0..=2*n {
                for y in 0..=2*n {
                    if count[x][y]!=c[x][y] {
                        // if (a,b)==(2,1) {
                        //     println!("{} {} {}",x,y,c[x][y]);
                        // }
                        flag = false;
                    }
                }
            }
            if flag {
                // println!("{} {}",a,b);
                ans[0] = (a,b);
            }
        }
    }
    let (s,t) = (ans[0].0 as i64, ans[0].1 as i64);
    for x in 0..=2*n {
        for y in 0..=2*n {
            if count[x][y]==1 {
                let idx = list[x][y][0];
                let a = x as i64 - n as i64;
                let b = y as i64 - n as i64;
                if 1<=(s-a)&&(s-a)<=(n-1) as i64&&0<=(t-b)&&(t-b)<=(n-1) as i64 {
                    ans[idx] = ((s-a) as usize,(t-b) as usize);
                }
                else {
                    ans[idx] = ((s-b) as usize,(t-a) as usize);
                }
            }
        }
    }
    for i in 0..total{
        for x in 0..=2*n {
            for y in 0..=2*n {
                if count[x][y]==2 {
                    let (idx1,idx2) = (list[x][y][0],list[x][y][1]);
                    let a = x as i64 - n as i64;
                    let b = y as i64 - n as i64;
                    let (a1,b1) = (s-a,t-b);
                    let (a2,b2) = (s-b,t-a);
                    let mut target = 0;
                    let mut td = (0,0);
                    for d in 1..total {
                        if ans[d]==(0,0) || d==idx1 || d==idx2 {
                            continue;
                        }
                        let (e,f) = (ans[d].0 as i64, ans[d].1 as i64);
                        let mut c1 = a1 - e;
                        let mut d1 = b1 - f;
                        let mut c2 = a2 - e;
                        let mut d2 = b2 - f;
                        if (min(c1,d1),max(c1,d1)) != (min(c2,d2),max(c2,d2)) {
                            target = d;
                            td = (min(c1,d1),max(c1,d1));
                            break;
                        }
                    }
                    // println!("{:?} {:?}",(a1,b1),(a2,b2));
                    // println!("{} {} {:?}",idx1,target,td);
                    if target==0 {
                        continue;
                    }
                    let (p,q) = query(idx1+1,target+1);
                    if (p,q)==td {
                        ans[idx1] = (a1 as usize, b1 as usize);
                        ans[idx2] = (a2 as usize, b2 as usize);
                    }
                    else {
                        ans[idx2] = (a1 as usize, b1 as usize);
                        ans[idx1] = (a2 as usize, b2 as usize);
                    }
                    count[x][y] = 0;
                }
            }
        }
    }
    print!("! ");
    for i in 0..total {
        print!("{} ",ans[i].0*n + ans[i].1);
    }
    println!();
}

fn query(x: usize, y: usize) -> (i64,i64) {
    println!("? {} {}", x, y);
    let ans = read!(i64,i64);
    ans
}

fn run() {
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    solve();
}
0