結果

問題 No.643 Two Operations No.2
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2018-02-02 21:41:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,403 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 93,224 KB
実行使用メモリ 5,460 KB
最終ジャッジ日時 2023-08-30 02:05:02
合計ジャッジ時間 1,623 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,372 KB
testcase_01 AC 3 ms
5,460 KB
testcase_02 AC 3 ms
5,320 KB
testcase_03 AC 3 ms
5,344 KB
testcase_04 AC 3 ms
5,416 KB
testcase_05 AC 3 ms
5,380 KB
testcase_06 AC 3 ms
5,332 KB
testcase_07 AC 4 ms
5,404 KB
testcase_08 AC 4 ms
5,352 KB
testcase_09 AC 3 ms
5,352 KB
testcase_10 AC 3 ms
5,348 KB
testcase_11 AC 3 ms
5,360 KB
testcase_12 AC 3 ms
5,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[510][510];

int main() {
	ll x,y;
	cin>>x>>y;
	clr(dp,-1);
	queue<ll> q1;
	queue<ll> q2;
	queue<ll> q3;
	q1.push(x+200);
	q2.push(y+200);
	q3.push(0);
	while(!q1.empty()){
		ll a = q1.front()-200;q1.pop();
		ll b = q2.front()-200;q2.pop();
		ll c = q3.front();q3.pop();
		if(a+200>500)continue;
		if(a+200<0)continue;
		if(b+200>500)continue;
		if(b+200<0)continue;
		if(dp[a+200][b+200]!=-1)continue;
		dp[a+200][b+200] = c;
		if(a==b){
			cout << c << endl;
			return 0;
		}
		q1.push(b+200);
		q2.push(a+200);
		q3.push(c+1);
		q1.push(a+b+200);
		q2.push(a-b+200);
		q3.push(c+1);
	}
	cout << -1 << endl;
	return 0;
}
0