結果

問題 No.643 Two Operations No.2
ユーザー pazzle1230pazzle1230
提出日時 2018-02-02 21:30:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,309 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 106,440 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 02:01:44
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <complex>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

map<PII, int> cnt;

int main(void){
	int x, y;
	cin >> x >> y;
	cnt[PII(x, y)] = -1;
	queue<PII> q;
	q.push({x, y});
	while(q.size()){
		x = q.front().first; y = q.front().second; q.pop();
		if(x == y){
			cout << (cnt[PII(x, y)] == -1 ? 0 : cnt[PII(x, y)]) << endl;
			return 0;
		}
		int now = cnt[PII(x, y)];
		if(now == -1) now = 0;
		if(cnt[PII(y, x)] == 0){
			cnt[PII(y, x)] = now+1;
			q.push({y, x});
		}
		if(abs(x+y) < 10000 && abs(x-y) < 10000 && cnt[PII(x+y, x-y)] == 0){
			cnt[PII(x+y, x-y)] = now+1;
			q.push({x+y, x-y});
		}
	}
	cout << -1 << endl;
}
0