結果

問題 No.594 壊れた宝物発見機
ユーザー aimyaimy
提出日時 2017-11-12 11:56:16
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 3,189 bytes
コンパイル時間 12,063 ms
コンパイル使用メモリ 401,040 KB
実行使用メモリ 25,616 KB
平均クエリ数 161.25
最終ジャッジ日時 2024-07-16 14:46:13
合計ジャッジ時間 16,002 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 AC 99 ms
24,836 KB
testcase_17 AC 100 ms
24,964 KB
testcase_18 WA -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> src/main.rs:60:9
   |
60 |     buf.trim_right().parse::<T>().ok().unwrap()
   |         ^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated method
   |
60 |     buf.trim_end().parse::<T>().ok().unwrap()
   |         ~~~~~~~~

warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> src/main.rs:75:22
   |
75 |     let mut it = buf.trim_right().split_whitespace();
   |                      ^^^^^^^^^^
   |
help: replace the use of the deprecated method
   |
75 |     let mut it = buf.trim_end().split_whitespace();
   |                      ~~~~~~~~

warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
  --> src/main.rs:93:22
   |
93 |     let mut it = buf.trim_right().split_whitespace();
   |                      ^^^^^^^^^^
   |
help: replace the use of the deprecated method
   |
93 |     let mut it = buf.trim_end().split_whitespace();
   |                      ~~~~~~~~

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

warning: use of deprecated method `core::str::<impl str>::trim_right`: superseded by `trim_end`
   --> src/main.rs:127:9
    |
127 |     buf.trim_right().chars().collect()
    |         ^^^^^^^^^^
    |
help: replace the use of the deprecated method
    |
127 |     buf.trim_end().chars().collect()
    |         ~~~~~~~~

ソースコード

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 {
  let mut dl = query(i, lo);
  let mut dr = query(i, hi);

  loop {
    let k1 = lo + (hi - lo) / 3;
    let k2 = hi - (hi - lo) / 3;
    let d1 = query(i, k1);
    let d2 = query(i, k2);
    match 0 {
      _ if dl<d1 && d1<d2 && d2<dr => {hi = k1; dr = query(i, hi)},
      _ if dl>d1 && d1<d2 => {hi = k2; dr = query(i, hi)},
      _ if d1>d2 && d2<dr => {lo = k1; dl = query(i, lo)},
      _ => {lo = k2; dl = query(i, lo)} 
    }
    if hi - lo == 2 {break}
  }

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

  match 0 {
    _ if d1<d2 && d1<d3 => {lo},
    _ if d3<d2 && d3<d1 => {hi},
    _ => {(lo+hi)/2}
  }
}

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

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

#[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