結果

問題 No.513 宝探し2
ユーザー masamasa
提出日時 2017-05-05 23:53:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 891 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 68,424 KB
実行使用メモリ 24,408 KB
平均クエリ数 64.50
最終ジャッジ日時 2023-09-23 13:51:32
合計ジャッジ時間 2,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 27 ms
23,544 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 27 ms
24,408 KB
testcase_06 WA -
testcase_07 AC 27 ms
23,856 KB
testcase_08 AC 25 ms
23,424 KB
testcase_09 AC 25 ms
23,724 KB
testcase_10 WA -
testcase_11 AC 27 ms
24,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

const int n_bit = 20;

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 += width / 2;
		} else {
			point -= width / 2;
		}

		width /= 2;
	}

	return point;
}

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

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

	return 0;
}
0