結果

問題 No.3018 目隠し宝探し
ユーザー srjywrdnprkt
提出日時 2025-03-16 01:25:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 3,189 ms
コンパイル使用メモリ 273,728 KB
実行使用メモリ 26,356 KB
平均クエリ数 2.68
最終ジャッジ日時 2025-03-16 01:25:47
合計ジャッジ時間 6,748 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/modint>

using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       H=1, W=1なら質問しなくて良い。
       H=1 (W=1)なら1からの距離(d-1)^2から特定できる。
       H>=2, W>=2なら(1, 1), (H, 1)からの距離がわかればそれらの交点はグリッド状に1つしかないのでわかる。
    */

    auto ans=[](int i, int j)->void{
        cout << "! " << i << " " << j << endl;
        exit(0);
    };
    auto ask=[](int i, int j)->int{
        cout << "? " << i << " " << j << endl;
        int res;
        cin >> res;
        if (res == -1) exit(0);
        return res;
    };

    int H, W, d, e;
    cin >> H >> W;
    if (H == 1 && W == 1) ans(1,1);
    if (H >= 2 && W >= 2){
        d = ask(1,1);
        e = ask(H,1);
        for (int i=1; i<=H; i++){
            for (int j=1; j<=W; j++){
                if ((i-1)*(i-1)+(j-1)*(j-1) == d && (H-i)*(H-i)+(j-1)*(j-1) == e) ans(i, j);
            }
        }
    }
    else{
        d = ask(1,1);
        for (int i=1; i<=H; i++){
            for (int j=1; j<=W; j++){
                if ((i-1)*(i-1)+(j-1)*(j-1) == d) ans(i, j);
            }
        }
    }

    return 0;
}
0