結果

問題 No.513 宝探し2
ユーザー masamasa
提出日時 2017-05-06 00:00:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 68,524 KB
実行使用メモリ 24,360 KB
平均クエリ数 49.00
最終ジャッジ日時 2023-09-24 01:09:34
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,976 KB
testcase_01 AC 25 ms
23,616 KB
testcase_02 AC 24 ms
24,360 KB
testcase_03 AC 25 ms
23,556 KB
testcase_04 AC 24 ms
23,220 KB
testcase_05 AC 23 ms
23,688 KB
testcase_06 AC 25 ms
23,628 KB
testcase_07 AC 26 ms
23,640 KB
testcase_08 AC 25 ms
23,592 KB
testcase_09 AC 25 ms
23,688 KB
testcase_10 AC 24 ms
24,012 KB
testcase_11 AC 23 ms
24,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int n_bit = 17;

int query(bool isX, int val) {
	if (isX) {
		cout << val << " 0"<< endl;
	} else {
		cout << "0 " << val << endl;
	}
	int ret;
	cin >> ret;

// printf("query val %3d, ret %3d\n", val, ret);
	return ret;
}

int calc(bool isX) {
	int width = (1 << n_bit) - 1;
	int point = 0;

	while (width > 0) {
// printf("-- point %3d width %3d\n", point, width);
		int r = point + width;
		int l = point - width;

		int r_val = query(isX, r);
		int l_val = query(isX, l);

		if (r_val == l_val) {
			return point;
		} else if (r_val < l_val) {
			point = r - width / 2;
		} else {
			point = l + width / 2;
		}

		width /= 2;
	}

	return point;
}

int main() {
	int x = calc(true);
	int y = calc(false);
	// int y = 0;

	cout << x << " " << y << endl;

	return 0;
}
0