結果

問題 No.513 宝探し2
ユーザー kichirb3kichirb3
提出日時 2018-03-08 19:55:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 63,832 KB
実行使用メモリ 24,072 KB
平均クエリ数 9.33
最終ジャッジ日時 2023-09-23 15:53:20
合計ジャッジ時間 1,695 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,652 KB
testcase_01 AC 24 ms
23,532 KB
testcase_02 AC 23 ms
24,060 KB
testcase_03 AC 23 ms
23,652 KB
testcase_04 AC 23 ms
23,652 KB
testcase_05 AC 22 ms
23,532 KB
testcase_06 AC 24 ms
24,048 KB
testcase_07 AC 23 ms
23,844 KB
testcase_08 AC 23 ms
23,664 KB
testcase_09 AC 23 ms
23,640 KB
testcase_10 AC 23 ms
24,072 KB
testcase_11 AC 23 ms
23,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.513 宝探し2
// https://yukicoder.me/problems/no/513
//

#include <iostream>
using namespace std;

int check_distance(int x, int y);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int dist;
    dist = check_distance(0, 0);
    int lx = 0;
    int rx = dist;
    
    bool lx_update = true;
    bool rx_update = true;
    int ldist = 0;
    int rdist = 0;
    
    while (dist != 0) {
        if (lx_update) {
            ldist = check_distance(lx, dist - lx);
            lx_update = false;
            if (ldist == 0)
                break;
        }
        if (rx_update) {
            rdist = check_distance(rx, dist - rx);
            rx_update = false;
            if (rdist == 0)
                break;
        }
        if (ldist == rdist) {
            lx = (lx + rx) / 2;
            lx_update = true;
        } else if (ldist < rdist) {
            rx = (lx + rx) / 2;
            rx_update = true;
        } else {
            lx = (lx + rx) / 2;
            lx_update = true;
        }
    }
}


int check_distance(int x, int y) {
    cout << x << " " << y << endl << flush; 
    int res;
    cin >> res;
    return res;
}
0