結果

問題 No.1306 Exactly 2 Digits
ユーザー ziitaziita
提出日時 2021-02-25 01:59:01
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 6,996 bytes
コンパイル時間 13,278 ms
コンパイル使用メモリ 403,116 KB
実行使用メモリ 25,476 KB
平均クエリ数 1236.78
最終ジャッジ日時 2024-07-17 10:38:23
合計ジャッジ時間 44,219 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,836 KB
testcase_01 WA -
testcase_02 AC 22 ms
24,836 KB
testcase_03 AC 22 ms
25,476 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 23 ms
24,836 KB
testcase_07 AC 23 ms
24,836 KB
testcase_08 AC 22 ms
24,580 KB
testcase_09 AC 23 ms
24,836 KB
testcase_10 AC 23 ms
25,220 KB
testcase_11 AC 22 ms
25,220 KB
testcase_12 AC 24 ms
24,836 KB
testcase_13 AC 23 ms
24,964 KB
testcase_14 AC 22 ms
24,580 KB
testcase_15 AC 22 ms
24,964 KB
testcase_16 WA -
testcase_17 AC 22 ms
24,580 KB
testcase_18 WA -
testcase_19 AC 23 ms
24,580 KB
testcase_20 AC 23 ms
24,580 KB
testcase_21 AC 22 ms
25,220 KB
testcase_22 WA -
testcase_23 AC 22 ms
24,836 KB
testcase_24 AC 25 ms
24,836 KB
testcase_25 AC 23 ms
25,220 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 23 ms
24,580 KB
testcase_29 AC 23 ms
24,964 KB
testcase_30 AC 23 ms
25,220 KB
testcase_31 AC 23 ms
24,964 KB
testcase_32 WA -
testcase_33 AC 23 ms
25,220 KB
testcase_34 WA -
testcase_35 AC 23 ms
24,824 KB
testcase_36 WA -
testcase_37 AC 23 ms
24,836 KB
testcase_38 WA -
testcase_39 AC 23 ms
24,836 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 24 ms
25,220 KB
testcase_44 WA -
testcase_45 AC 26 ms
24,580 KB
testcase_46 AC 25 ms
24,580 KB
testcase_47 AC 27 ms
24,964 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 35 ms
25,220 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 45 ms
24,836 KB
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 WA -
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 AC 253 ms
25,476 KB
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 AC 227 ms
24,964 KB
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 WA -
testcase_111 WA -
testcase_112 AC 212 ms
24,964 KB
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 WA -
testcase_120 AC 225 ms
24,964 KB
testcase_121 WA -
testcase_122 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
                        }
                    }
                    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