結果
問題 |
No.594 壊れた宝物発見機
|
ユーザー |
|
提出日時 | 2017-11-10 23:14:27 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 3,346 bytes |
コンパイル時間 | 18,620 ms |
コンパイル使用メモリ | 384,592 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 27.40 |
最終ジャッジ日時 | 2024-07-16 14:31:22 |
合計ジャッジ時間 | 20,774 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#[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 binsearch(axis: usize, low: i64, high: i64, cache: &mut HashMap<i64, usize>) -> i64 { let l = match cache.get(&low).cloned() { Some(x) => x, _ => bask(axis, low), }; let r = match cache.get(&high).cloned() { Some(x) => x, _ => bask(axis, high), }; cache.insert(low, l); cache.insert(high, r); let mid = (low + high) / 2; if low + 1 == high { match l.cmp(&r) { Ordering::Less => low, // Impossible Ordering::Equal => low, Ordering::Greater => high, } } else { match l.cmp(&r) { Ordering::Less => binsearch(axis, low, mid, cache), Ordering::Equal => mid, Ordering::Greater => binsearch(axis, mid, high, cache), } } } fn main() { let x = binsearch(0, -150, 150, &mut HashMap::new()); let y = binsearch(1, -150, 150, &mut HashMap::new()); let z = binsearch(2, -150, 150, &mut HashMap::new()); println!("! {} {} {}", x, y, z); }