結果

問題 No.513 宝探し2
コンテスト
ユーザー umaumax
提出日時 2017-05-05 23:21:38
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,352 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 356 ms
コンパイル使用メモリ 73,204 KB
最終ジャッジ日時 2026-03-31 15:44:17
合計ジャッジ時間 727 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main(int, const char**)':
main.cpp:10:13: error: 'uint64_t' was not declared in this scope
   10 |         map<uint64_t, int> m;
      |             ^~~~~~~~
main.cpp:5:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    4 | #include <map>
  +++ |+#include <cstdint>
    5 | 
main.cpp:10:26: error: template argument 1 is invalid
   10 |         map<uint64_t, int> m;
      |                          ^
main.cpp:10:26: error: template argument 3 is invalid
main.cpp:10:26: error: template argument 4 is invalid
main.cpp: In lambda function:
main.cpp:14:23: error: 'key' was not declared in this scope
   14 |                 if (m[key]) return m[key];
      |                       ^~~
main.cpp:19:19: error: 'key' was not declared in this scope
   19 |                 m[key] = d;
      |                   ^~~
main.cpp: In lambda function:
main.cpp:24:23: error: 'key' was not declared in this scope
   24 |                 if (m[key]) return m[key];
      |                       ^~~
main.cpp:29:19: error: 'key' was not declared in this scope
   29 |                 m[key] = d;
      |                   ^~~

ソースコード

diff #
raw source code

#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