結果

問題 No.594 壊れた宝物発見機
ユーザー aimyaimy
提出日時 2017-11-12 16:49:04
言語 Rust
(1.77.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 3,068 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 140,920 KB
実行使用メモリ 24,312 KB
平均クエリ数 65.70
最終ジャッジ日時 2023-09-23 15:05:44
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
23,364 KB
testcase_01 AC 107 ms
23,580 KB
testcase_02 AC 106 ms
23,952 KB
testcase_03 AC 106 ms
23,940 KB
testcase_04 AC 106 ms
24,312 KB
testcase_05 AC 105 ms
23,328 KB
testcase_06 AC 105 ms
23,784 KB
testcase_07 AC 106 ms
23,568 KB
testcase_08 AC 105 ms
23,616 KB
testcase_09 AC 105 ms
24,012 KB
testcase_10 AC 105 ms
24,312 KB
testcase_11 AC 104 ms
23,772 KB
testcase_12 AC 104 ms
23,424 KB
testcase_13 AC 106 ms
23,472 KB
testcase_14 AC 105 ms
23,772 KB
testcase_15 AC 103 ms
23,628 KB
testcase_16 AC 103 ms
24,300 KB
testcase_17 AC 103 ms
24,276 KB
testcase_18 AC 103 ms
23,556 KB
testcase_19 AC 101 ms
23,844 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> Main.rs:58:9
   |
58 |     buf.trim_right().parse::<T>().ok().unwrap()
   |         ^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated associated function
   |
58 |     buf.trim_end().parse::<T>().ok().unwrap()
   |         ~~~~~~~~

warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> Main.rs:73:22
   |
73 |     let mut it = buf.trim_right().split_whitespace();
   |                      ^^^^^^^^^^
   |
help: replace the use of the deprecated associated function
   |
73 |     let mut it = buf.trim_end().split_whitespace();
   |                      ~~~~~~~~

warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> Main.rs:91:22
   |
91 |     let mut it = buf.trim_right().split_whitespace();
   |                      ^^^^^^^^^^
   |
help: replace the use of the deprecated associated function
   |
91 |     let mut it = buf.trim_end().split_whitespace();
   |                      ~~~~~~~~

warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
   --> Main.rs:110:9
    |
110 |     buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
    |         ^^^^^^^^^^
    |
help: replace the use of the deprecated associated function
    |
110 |     buf.trim_end().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
    |         ~~~~~~~~

warning: use of deprecated associated function `core::str::<impl str>::trim_right`: superseded by `trim_end`
   --> Main.rs:125:9
    |
125 |     buf.trim_right().chars().collect()
    |         ^^^^^^^^^^
    |
help: replace the use of the deprecated associated function
    |
125 |     buf.trim_end().chars().collect()
    |         ~~~~~~~~

warning: 5 warnings emitt

ソースコード

diff #

fn main() {
  let x = trisearch(0, -100, 100);
  let y = trisearch(1, -100, 100);
  let z = trisearch(2, -100, 100);

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

fn trisearch(i: usize, mut lo: i32, mut hi: i32) -> i32 {
  use std::cmp::Ordering::*;

  while hi - lo > 2 {
    let k1 = lo + (hi - lo) / 3;
    let k2 = hi - (hi - lo) / 3;
    let d1 = query(i, k1);
    let d2 = query(i, k2);
    match d1.cmp(&d2) {
      Less    => {hi = k2},
      Greater => {lo = k1},
      Equal   => {lo = k1; hi = k2}
    }
  }

  let d1 = query(i, lo);
  let d2 = query(i, (lo+hi)/2);
  let d3 = query(i, hi);

  match [d1,d2,d3].iter().min().unwrap() {
    &d if d == d1 => lo,
    &d if d == d3 => hi,
    _             => (lo + hi) / 2
  }
}

fn getd(x: i32, y: i32, z: i32) -> i32 {
  println!("? {} {} {}", x, y, z);
  get::val::<i32>()
}

fn query(i: usize, k: i32) -> i32 {
  match i {
    0 => getd(k, 0, 0),
    1 => getd(0, k, 0),
    2 => getd(0, 0, k),
    _ => unreachable!()
  }
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}
0