結果

問題 No.643 Two Operations No.2
ユーザー bal4ubal4u
提出日時 2019-07-13 10:56:28
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 28,820 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 21:48:23
合計ジャッジ時間 1,389 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.643 Two Operations No.2
// 2019.7.13 bal4u

#include <stdio.h>

#define SFT 500
#define MAX 1000
#define ABS(x) ((x)>=0?(x):-(x))
typedef struct { int x, y, s; } Q;
Q q[100000]; int top, end;
char vis[MAX+2][MAX+2];

int main()
{
	int x, y, s, ans = -1;

	scanf("%d%d", &x, &y);
	q[0].x = x, q[0].y = y, end = 1;
	while (top != end) {
		x = q[top].x, y = q[top].y, s = q[top++].s;
		if (x == y) { ans = s; break; }
		if (vis[SFT+x][SFT+y]) continue;
		vis[SFT+x][SFT+y] = 1;
		q[end].x = y, q[end].y = x, q[end++].s = s+1;
		if (ABS(x+y) <= SFT && ABS(x-y) <= SFT)
			q[end].x = x+y, q[end].y = x-y, q[end++].s = s+1;
	}
	printf("%d\n", ans);
	return 0;
}
0