結果

問題 No.3018 目隠し宝探し
ユーザー tsunamayo123
提出日時 2025-01-25 13:45:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 195,428 KB
実行使用メモリ 25,972 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-01-25 22:57:59
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge9 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int question(int, int)’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d",&d);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

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

int question(int i,int j){
    printf("? %d %d\n",i,j);
    fflush(stdout);
    int d;
    scanf("%d",&d);
    return d;
}

void answer(int i,int j){
    printf("! %d %d\n",i,j);
    fflush(stdout);
}

int main(){
    int H,W; cin>>H>>W;
    if(H==1&&W==1){
        answer(1,1);
        return 0;
    }

    int d1=question(1,1);

    vector<pair<int,int>> D;

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            int dist1=(i-1)*(i-1)+(j-1)*(j-1);
            if(dist1==d1){
                D.push_back({i,j});
            }
        }
    }

    if(D.size()==1){
        answer(D[0].first,D[0].second);
        return 0;
    }

    D.clear();

    int d2=question(H,1);

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            int dist1=(i-1)*(i-1)+(j-1)*(j-1);
            int dist2=(i-H)*(i-H)+(j-1)*(j-1);
            if(dist1==d1 && dist2==d2){
                D.push_back({i,j});
            }
        }
    }

    if(D.size()==1){
        answer(D[0].first,D[0].second);
        return 0;
    }

    int d3=question(D[0].first,D[0].second);
    if(d3==-1)return 1;

    if(d3==0)answer(D[0].first,D[0].second);
    else answer(D[1].first,D[1].second);

    return 0;
}
0