結果

問題 No.594 壊れた宝物発見機
ユーザー face4face4
提出日時 2018-08-27 11:31:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,288 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 65,348 KB
実行使用メモリ 24,432 KB
平均クエリ数 76.80
最終ジャッジ日時 2023-09-23 16:16:08
合計ジャッジ時間 4,349 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 三分探索を関数化してプログラムをすっきりさせたい
#include<iostream>
using namespace std;

int ask(int x, int y, int z){
    int d;
    cout << "? " << x << " " << y << " " << z << endl;
    cin >> d;
    return d;
}

void answer(int x, int y, int z){
    cout << "! " << x << " " << y << " " << z << endl;
}

int main(){
    int lx = -150, rx = 150, ly = -150, ry = 150, lz = -150, rz = 150;
    int x, y = 0, z = 0;

    while(lx+2 < rx){
        int mid1 = (rx-lx)/3+lx, mid2 = (rx-lx)*2/3+lx;
        int ask1 = ask(mid1,y,z);
        int ask2 = ask(mid2,y,z);
        if(ask1 <= ask2){
            rx = mid2;
        }else{
            lx = mid1;
        }
    }

    x = (lx+rx)/2;
    
    while(ly+2 < ry){
        int mid1 = (ry-ly)/3+ly, mid2 = (ry-ly)*2/3+ly;
        int ask1 = ask(x,ly,z);
        int ask2 = ask(x,ry,z);
        if(ask1 <= ask2){
            ry = mid2;
        }else{
            ly = mid1;
        }
    }

    y = (ly+ry)/2;

    while(lz+2 < rz){
        int mid1 = (rz-lz)/3+lz, mid2 = (rz-lz)*2/3+lz;
        int ask1 = ask(x,lz,z);
        int ask2 = ask(x,rz,z);
        if(ask1 <= ask2){
            rz = mid2;
        }else{
            lz = mid1;
        }
    }

    y = (ly+ry)/2;

    answer(x, y, z);

    return 0;
}
0