結果

問題 No.594 壊れた宝物発見機
ユーザー とばりとばり
提出日時 2018-09-07 19:08:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 165,500 KB
実行使用メモリ 24,336 KB
平均クエリ数 50.40
最終ジャッジ日時 2023-09-23 16:18:51
合計ジャッジ時間 5,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
24,288 KB
testcase_01 AC 99 ms
24,324 KB
testcase_02 AC 98 ms
23,664 KB
testcase_03 AC 99 ms
23,400 KB
testcase_04 AC 98 ms
23,448 KB
testcase_05 AC 101 ms
24,012 KB
testcase_06 AC 102 ms
23,424 KB
testcase_07 AC 99 ms
23,544 KB
testcase_08 AC 98 ms
24,312 KB
testcase_09 AC 99 ms
23,412 KB
testcase_10 AC 100 ms
24,036 KB
testcase_11 AC 99 ms
23,880 KB
testcase_12 AC 100 ms
23,472 KB
testcase_13 AC 99 ms
23,700 KB
testcase_14 AC 103 ms
24,336 KB
testcase_15 AC 101 ms
23,472 KB
testcase_16 AC 102 ms
23,688 KB
testcase_17 AC 99 ms
23,580 KB
testcase_18 AC 102 ms
23,460 KB
testcase_19 AC 101 ms
15,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using int64 = long long;
using uint64 = unsigned long long;

int ask(int pi, int n)
{
    cout << "?";
    for (int i = 0; i < 3; i++)
    {
        cout << " " << (i == pi ? n : 0);
    }
    cout << endl;

    int D;
    cin >> D;
    return D;
}

// 第i成分を複数回の質問により特定する
int determine(int pi)
{
    int lb = -151, ub = 150;
    while (ub - lb > 1)
    {
        int mid = (ub + lb) / 2;

        int D1 = ask(pi, mid),
            D2 = ask(pi, mid + 1);
        
        assert(D1 >= 0 and D2 >= 0);

        if (D1 <= D2) ub = mid;
        else lb = mid;
    }
    return ub;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int x = determine(0),
        y = determine(1),
        z = determine(2);
    
    cout << "! " << x << " " << y << " " << z << endl;

    return 0;
}
0