結果

問題 No.3018 目隠し宝探し
ユーザー Jikky1618
提出日時 2025-01-25 14:53:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,848 bytes
コンパイル時間 3,270 ms
コンパイル使用メモリ 275,368 KB
実行使用メモリ 87,584 KB
最終ジャッジ日時 2025-01-25 23:33:13
合計ジャッジ時間 73,405 ms
ジャッジサーバーID
(参考情報)
judge9 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 1
other TLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

// 離散関数 f: Z -> R の区間 [left, right] での黄金分割探索
template <class T, class F>
auto golden_section_search(ll left, ll right, F&& f, bool maximize = true) {
    ll a = left - 1, x, b;
    {
        ll s = 1, t = 2;
        while (t < right - left + 2) swap(s += t, t);
        x = a + t - s, b = a + t;
    }
    T fx = f(x);
    while (a + b != 2 * x) {
        ll y = a + b - x;
        T fy = f(y);
        if (right < y || maximize ? fx < fy : fx > fy) {
            a = x, x = y, fx = fy;
        } else {
            b = a, a = y;
        }
    }
    return make_pair(x, fx);
}

// N は平方数, 0 <= N <= 4.5*10^18 < 2^62
ll integer_sqrt(ll N) {
    // √N < 2^31
    ll low = -1, high = 1LL << 31;
    while (high - low > 1) {
        ll mid = (low + high) / 2, mid2 = mid * mid;
        if (mid2 <= N) {
            low = mid;
        } else {
            high = mid;
        }
    }
    return low;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int H, W;
    cin >> H >> W;

    // H を特定
    // int local_ans_h = 17, local_ans_w = 334;
    auto check = [&](int h, int w) -> int {
        // cout << "? " << h << " " << w << endl;
        // int d = (local_ans_h - h) * (local_ans_h - h) + (local_ans_w - w) * (local_ans_w - w);
        int d;
        cin >> d;
        if (d == -1) exit(0);
        return d;
    };
    auto f1 = [&](int h) -> int { return check(h, 1); };
    auto [h, d1] = golden_section_search<int>(1, H, f1, false);
    auto f2 = [&](int w) -> int { return check(h, w); };
    auto [w, d2] = golden_section_search<int>(1, W, f2, false);
    cout << "! " << h << " " << w << endl;
}
0