結果

問題 No.513 宝探し2
ユーザー umaumaxumaumax
提出日時 2017-05-05 23:21:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,352 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 73,816 KB
実行使用メモリ 35,700 KB
最終ジャッジ日時 2023-09-24 01:07:46
合計ジャッジ時間 6,975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 134, ay = 2332;
	auto fxy = [&](int x, int y) {
		uint64_t key = 100001 * (y + 1) + x;
		if (m[key]) return m[key];
		//		cout << x << " " << y << endl;
		//		return abs(ax - x) + abs(ay - y);
		int d;
		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;
		//		return abs(ax - y) + abs(ay - x);
		int d;
		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;
				break;
			}
			if (gap <= 1) break;
		}
		//		cout << "x=" << x << endl;
		if (i == 100) break;
		y	 = x;
		x	 = 0;
		lowX  = 0;
		highX = 100000;
		f	 = fyx;
		i++;
	}
	return 0;
}
0