結果

問題 No.240 ナイト散歩
コンテスト
ユーザー spacia
提出日時 2016-01-04 20:56:11
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 44 ms / 2,000 ms
+ 473µs
コード長 799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,598 ms
コンパイル使用メモリ 85,784 KB
実行使用メモリ 41,784 KB
最終ジャッジ日時 2026-09-11 17:15:25
合計ジャッジ時間 4,598 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	static int goalX , goalY;
	static int[] dx = {-2,-2,-1,-1,1,1,2,2};
	static int[] dy = {-1,1,-2,2,-2,2,-1,1};
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static void solve (int x , int y , int n) {
		if (x == goalX && y == goalY) {
			out("YES");
			System.exit(0);
		}
		if (n == 3) return;
		
		for (int i = 0; i < dx.length; i++) {
			solve(x + dx[i] , y + dy[i] , n + 1);
		}
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		String[] line = br.readLine().split(" ");
		goalX = Integer.parseInt(line[0]);
		goalY = Integer.parseInt(line[1]);
		
		solve(0 , 0 , 0);
		
		out("NO");
	}
}
0