結果

問題 No.3018 目隠し宝探し
ユーザー ooaiu
提出日時 2025-02-01 20:06:11
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 5,773 ms
コンパイル使用メモリ 277,176 KB
実行使用メモリ 26,228 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-02-01 20:06:21
合計ジャッジ時間 8,825 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
void ans(int i, int j) {
    cout << "! " << i << " " << j << endl;
    exit(0);
}
int ask(int i, int j) {
    cout << "? " << i << " " << j << endl;
    int d;
    cin >> d;
    if(d == 0) ans(i, j);
    assert(d != -1);
    return d;
}
int dist(int x, int y) { return x * x + y * y; }
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int H, W;
    cin >> H >> W;
    if(H == 1 && W == 1) ans(1, 1);
    int d1 = ask(1, 1);
    vector<pair<int, int>> ss;
    for(int i = 1; i <= H; i++) for(int j = 1; j <= W; j++) {
        if(dist(i - 1, j - 1) == d1) ss.push_back({i, j});
    }
    if(ss.size() == 1) {
        ans(ss.front().first, ss.front().second);
    }
    int d2 = ask(1, W);
    for(const auto&[i, j]: ss) {
        if(dist(i - 1, W - j) == d2) {
            ans(i, j);
        }
    }
}
0