結果

問題 No.643 Two Operations No.2
ユーザー masamasa
提出日時 2018-02-02 22:31:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 02:18:42
合計ジャッジ時間 1,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;
using PII = pair<int, int>;

const int wide = 1000;

vector<vector<bool>> check_dat;

bool check(int x, int y) {
	return check_dat[x + wide][y + wide];
}

void checked(int x, int y, bool val) {
	check_dat[x + wide][y + wide] = val;
}

int main() {
	int x, y, x2, y2;
	cin >> x >> y;

	if (x == y) {
		cout << 0 << endl;
		return 0;
	}
	if (abs(x - y) % 2 == 1) {
		cout << -1 << endl;
		return 0;
	}

	check_dat.assign(2 * wide + 1, vector<bool>(2 * wide + 1, false));
	checked(x, y, true);

	vector<PII> v1, v2;
	v1.emplace_back(make_pair(x, y));

	int ans = 0;
	while (!v1.empty()) {
		v2.clear();
		ans++;
		for (auto p : v1) {
			x = p.first;
			y = p.second;
			x2 = y;
			y2 = x;

			if (!check(x2, y2)) {
				checked(x, y, true);
				v2.emplace_back(make_pair(x2, y2));
			}

			x2 = x + y;
			y2 = x - y;

			if (x2 == y2) {
				cout << ans << endl;
				return 0;
			}

			if (abs(x2) > wide || abs(y2) > wide) {
				continue;
			}

			if (!check(x2, y2)) {
				checked(x, y, true);
				v2.emplace_back(make_pair(x2, y2));
			}
		}
		v1 = v2;
	}

	cout << -1 << endl;
	return 0;
}
0