結果

問題 No.3018 目隠し宝探し
ユーザー yiwiy9
提出日時 2025-01-25 19:17:43
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 11,545 ms
コンパイル使用メモリ 379,648 KB
実行使用メモリ 25,984 KB
平均クエリ数 2.68
最終ジャッジ日時 2025-01-26 00:03:12
合計ジャッジ時間 14,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::{input, source::line::LineSource};
use std::io::{stdin, stdout, BufReader, Write};

/// https://yukicoder.me/problems/no/3018
/// https://yukicoder.me/problems/no/3018/editorial
fn main() {
    let stdin = stdin();
    let mut source = LineSource::new(BufReader::new(stdin.lock()));

    input! {
        from &mut source,
        h: i32,
        w: i32,
    }

    if h == 1 && w == 1 {
        println!("! 1 1");
        return;
    }

    println!("? {} {}", 1, 1);
    stdout().flush().unwrap();

    input! {
        from &mut source,
        d: i32,
    }

    let d_root = (d as f64).sqrt() as i32;

    if h == 1 {
        println!("! 1 {}", d_root);
        return;
    }
    if w == 1 {
        println!("! {} 1", d_root);
        return;
    }

    println!("? {} {}", 1, w);
    stdout().flush().unwrap();

    input! {
        from &mut source,
        d_h: i32,
    }

    for i in 1..=h {
        for j in 1..=w {
            if (i - 1) * (i - 1) + (j - 1) * (j - 1) == d
                && (i - 1) * (i - 1) + (j - w) * (j - w) == d_h
            {
                println!("! {} {}", i, j);
                return;
            }
        }
    }
}
0