結果

問題 No.3018 目隠し宝探し
ユーザー hirakuuuu
提出日時 2025-01-25 13:57:48
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,940 bytes
コンパイル時間 3,503 ms
コンパイル使用メモリ 281,964 KB
実行使用メモリ 87,124 KB
平均クエリ数 2.14
最終ジャッジ日時 2025-01-25 23:03:48
合計ジャッジ時間 18,545 ms
ジャッジサーバーID
(参考情報)
judge7 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 17 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define inr(l, x, r) (l <= x && x < r)
#define ll long long
#define ld long double

// using mint = modint1000000007;
// using mint = modint998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1e18;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int h, w; cin >> h >> w;

    cout << "? " << 1 << ' ' << 1 << endl;
    int d; cin >> d;
    set<pair<int, int>> s;
    {
        rep(i, 1, h+1) rep(j, 1, w+1){
            if((i-1)*(i-1)+(j-1)*(j-1) == d){
                s.insert({i, j});
            }
        }
        if(s.size() == 1){
            cout << "! " << (*s.begin()).first << ' ' << (*s.begin()).second << endl;
            return 0;
        }
    }

    cout << "? " << h << ' ' << w << endl;
    cin >> d;
    {
        set<pair<int, int>> s_;
        for(auto [i, j]: s){
            if((i-h)*(i-h)+(j-w)*(j-w) == d){
                s_.insert({i, j});
            }
        }
        swap(s_, s);
        if(s.size() == 1){
            cout << "! " << (*s.begin()).first << ' ' << (*s.begin()).second << endl;
            return 0;
        }
    }

    while(true){
        int i0 =  (*s.begin()).first, j0 = (*s.begin()).second;
        cout << "? " << i0 << ' ' << j0 << endl;
        cin >> d;
        {
            set<pair<int, int>> s_;
            for(auto [i, j]: s){
                if((i-i0)*(i-i0)+(j-j0)*(j-j0) == d){
                    s_.insert({i, j});
                }
            }
            swap(s_, s);
            if(s.size() == 1){
                cout << "! " << (*s.begin()).first << ' ' << (*s.begin()).second << endl;
                return 0;
            }
        }
    }



    
    return 0;
}
0