結果

問題 No.240 ナイト散歩
コンテスト
ユーザー ゴリポン先生
提出日時 2026-04-29 16:58:23
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,578 ms
コンパイル使用メモリ 194,048 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-29 16:58:29
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

module main;
// 幅優先探索
import std;

alias P = Tuple!(int, "x", int, "y");
auto knightMove = [
	P(1, 2), P(1, -2), P(-1, 2), P(-1, -2),
	P(2, 1), P(2, -1), P(-2, 1), P(-2, -1)
];

void main()
{
	// 入力
	int X, Y;
	readln.chomp.formattedRead("%d %d", X, Y);
	// 答えの計算
	int[P] dist;
	dist[P(0, 0)] = 0;
	auto que = DList!P(P(0, 0));
	while (!que.empty) {
		P now = que.front;
		que.removeFront;
		foreach (m; knightMove) {
			int nx = now.x + m.x, ny = now.y + m.y;
			if (P(nx, ny) in dist)
				continue;
			int nd = dist[now] + 1;
			if (nd > 3)	// 動けるのは3歩まで
				continue;
			dist[P(nx, ny)] = nd;
			que.insertBack(P(nx, ny));
		}
	}
	// 答えの出力
	writeln(P(X, Y) in dist ? "YES" : "NO");
}
0