結果

問題 No.3018 目隠し宝探し
ユーザー Tatsu_mr
提出日時 2025-01-25 15:11:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,809 bytes
コンパイル時間 3,685 ms
コンパイル使用メモリ 280,704 KB
実行使用メモリ 26,096 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-01-25 23:42:00
合計ジャッジ時間 7,422 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()

using lint = long long;
using ld = long double;

int INF = 2000000000;
lint LINF = 1000000000000000000;

int dist(int i, int j, int ii, int jj) {
    int dii = abs(i - ii);
    int djj = abs(j - jj);
    return dii * dii + djj * djj;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    if (h == 1 && w == 1) {
    	cout << "! " << 1 << " " << 1 << "\n";
    	cout.flush();
    	return 0;
    }
    auto ask = [](int i, int j) -> int {
        cout << "? " << i << " " << j << "\n";
        cout.flush();
        int d;
        cin >> d;
        return d;
    };
    int i = 1, j = 1;
    auto nextij = [&]() -> void {
        j++;
        if (j == w + 1) {
            i++;
            j = 1;
        }
    };
    int d = ask(i, j);
    set<pair<int, int>> s;
    For(i, 1, h + 1) {
        For(j, 1, w + 1) {
            if (dist(i, j, 1, 1) == d) {
                s.insert({i, j});
            }
        }
    }
    while (s.size() > 1) {
        nextij();
        int d = ask(i, j);
        if (d == 0) {
            cout << "! " << i << " " << j << "\n";
            cout.flush();
            return 0;
        }
        auto it = s.begin();
        while (it != s.end()) {
            auto [ii, jj] = *it;
            if (dist(i, j, ii, jj) != d) {
                it = s.erase(it);
            } else {
                it = next(it);
            }
        }
    }
    auto [ansi, ansj] = *s.begin();
    cout << "! " << ansi << " " << ansj << "\n";
    cout.flush();
    return 0;
}
0