結果

問題 No.594 壊れた宝物発見機
ユーザー hatoohatoo
提出日時 2017-11-11 17:09:10
言語 Rust
(1.77.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 3,174 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 152,828 KB
実行使用メモリ 24,432 KB
平均クエリ数 52.10
最終ジャッジ日時 2023-09-23 15:03:15
合計ジャッジ時間 4,152 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
23,580 KB
testcase_01 AC 100 ms
23,328 KB
testcase_02 AC 101 ms
23,448 KB
testcase_03 AC 101 ms
24,312 KB
testcase_04 AC 101 ms
24,060 KB
testcase_05 AC 99 ms
24,432 KB
testcase_06 AC 98 ms
23,328 KB
testcase_07 AC 97 ms
23,304 KB
testcase_08 AC 101 ms
24,072 KB
testcase_09 AC 102 ms
23,340 KB
testcase_10 AC 99 ms
23,664 KB
testcase_11 AC 101 ms
23,940 KB
testcase_12 AC 102 ms
24,072 KB
testcase_13 AC 99 ms
23,580 KB
testcase_14 AC 99 ms
23,580 KB
testcase_15 AC 98 ms
23,940 KB
testcase_16 AC 102 ms
23,460 KB
testcase_17 AC 100 ms
23,952 KB
testcase_18 AC 101 ms
23,604 KB
testcase_19 AC 98 ms
24,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn ask(x: i64, y: i64, z: i64) -> usize {
    println!("? {} {} {}", x, y, z);
    get!(usize)
}

fn bask(axis: usize, v: i64) -> usize {
    match axis {
        0 => ask(v, 0, 0),
        1 => ask(0, v, 0),
        2 => ask(0, 0, v),
        _ => 0,
    }
}

fn tri_search(axis: usize, low: i64, high: i64, cache: &mut HashMap<i64, usize>) -> i64 {
    if low == high {
        return low;
    }

    let t1 = low + max((high - low) / 3, 1);
    let t2 = high - max((high - low) / 3, 1);

    let l = cache.get(&t1).cloned().unwrap_or_else(|| bask(axis, t1));
    let r = cache.get(&t2).cloned().unwrap_or_else(|| bask(axis, t2));

    cache.insert(t1, l);
    cache.insert(t2, r);

    match l.cmp(&r) {
        Ordering::Less => tri_search(axis, low, t2, cache),
        Ordering::Equal => tri_search(axis, t1, t2, cache),
        Ordering::Greater => tri_search(axis, t1, high, cache),
    }
}

fn main() {
    let x = tri_search(0, -150, 150, &mut HashMap::new());
    let y = tri_search(1, -150, 150, &mut HashMap::new());
    let z = tri_search(2, -150, 150, &mut HashMap::new());

    println!("! {} {} {}", x, y, z);
}
0