結果

問題 No.643 Two Operations No.2
ユーザー masamasa
提出日時 2018-02-02 22:01:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 375 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 66,080 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-08-30 02:10:57
合計ジャッジ時間 4,129 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

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

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

	int ans = 0;
	while (x != y) {
		int x2 = x + y;
		int y2 = x - y;

		if (abs(x2 - y2) < abs(x - y)) {
			x = x2;
			y = y2;
		} else {
			swap(x, y);
		}
		ans++;
	}

	cout << ans << endl;
	return 0;
}
0