結果

問題 No.240 ナイト散歩
ユーザー Tsukasa_Type
提出日時 2018-03-26 22:36:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 54,332 KB
最終ジャッジ日時 2024-06-25 12:12:56
合計ジャッジ時間 7,578 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.System.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int gx = sc.nextInt();
	static int gy = sc.nextInt();
	public static void main(String[] args) {
		out.println(dfs(0,0,0)?"YES":"NO");
	}
	static boolean dfs(int x, int y, int n) {
		if (n>3) return false;
		if (x==gx && y==gy) return true;
		return (
				dfs(x-2,y-1,n+1) ||
				dfs(x-2,y+1,n+1) ||
				dfs(x-1,y-2,n+1) ||
				dfs(x-1,y+2,n+1) ||
				dfs(x+1,y-2,n+1) ||
				dfs(x+1,y+2,n+1) ||
				dfs(x+2,y-1,n+1) ||
				dfs(x+2,y+1,n+1)
		);
	}
}
0