結果

問題 No.513 宝探し2
ユーザー umaumaxumaumax
提出日時 2017-05-05 23:27:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,605 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 75,832 KB
実行使用メモリ 24,420 KB
平均クエリ数 20.75
最終ジャッジ日時 2023-09-24 01:08:11
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,252 KB
testcase_01 AC 26 ms
23,904 KB
testcase_02 AC 26 ms
24,264 KB
testcase_03 AC 26 ms
24,264 KB
testcase_04 AC 26 ms
23,508 KB
testcase_05 AC 25 ms
23,820 KB
testcase_06 AC 25 ms
23,316 KB
testcase_07 AC 25 ms
24,324 KB
testcase_08 AC 24 ms
23,928 KB
testcase_09 AC 24 ms
23,352 KB
testcase_10 AC 25 ms
23,472 KB
testcase_11 AC 25 ms
24,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>

using namespace std;

int main(int argc, const char* argv[])
{
	map<uint64_t, int> m;
	//	int ax = 10000, ay = 1234;
	int ax = -1, ay = -1;
	auto fxy = [&](int x, int y) {
		uint64_t key = 100001 * (y + 1) + x;
		if (m[key]) return m[key];
		cout << x << " " << y << endl;
		int d = abs(ax - x) + abs(ay - y);
		if (ax == -1 && ay == -1) {
			cin >> d;
		}
		m[key] = d;
		return d;
	};
	auto fyx = [&](int x, int y) {
		uint64_t key = 100001 * (x + 1) + y;
		if (m[key]) return m[key];
		cout << y << " " << x << endl;
		int d = abs(ax - y) + abs(ay - x);
		if (ax == -1 && ay == -1) {
			cin >> d;
		}
		m[key] = d;
		return d;
	};
	int lowX = 0;
	//	int lowY  = 0;
	int highX = 100000;
	//	int highY = 100000;
	int x = 0;
	int y = 0;
	//	auto f = fxy;
	function<int(int, int)> f = fxy;
	int i = 0;
	for (int k = 0; k < 2; k++) {
		for (; i < 100; i++) {
			int ld = f(lowX, y);
			if (ld == 0) return 0;
			int hd = f(highX, y);
			if (hd == 0) return 0;
			int gap = highX - lowX;
			if (ld < hd) {
				x = lowX;
				highX -= gap / 2;
			}
			if (ld > hd) {
				x = highX;
				lowX += gap / 2;
			}
			if (ld == hd) {
				x = (lowX + highX) / 2;
				if (k == 1) {
					int d = f(x, y);
					if (d == 0) return 0;
				}
				break;
			}
			if (gap <= 1) break;
		}
		if (ax == -1 && ay == -1) {
		}
		else
			cout << "x or y =" << x << endl;
		if (i == 100) break;
		y	 = x;
		x	 = 0;
		lowX  = 0;
		highX = 100000;
		f	 = fyx;
		i++;
	}
	if (ax == -1 && ay == -1) {
	}
	else
		cout << "x or y =" << x << endl;
	return 0;
}
0