結果

問題 No.240 ナイト散歩
コンテスト
ユーザー 37zigen
提出日時 2016-05-01 16:03:01
言語 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  
実行時間 57 ms / 2,000 ms
+ 959µs
コード長 998 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,659 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 43,868 KB
最終ジャッジ日時 2026-09-11 17:17:56
合計ジャッジ時間 5,346 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package yukicoder;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
public class Main{
	int[] dx={2,2,-2,-2,1,-1,1,-1};
	int[] dy={1,-1,1,-1,2,2,-2,-2};
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt()+500;
		int y=sc.nextInt()+500;
		Queue<Coordinate> q=new ArrayDeque<Coordinate>();
		boolean[][] arrived=new boolean[1000][1000];
		
		q.add(new Coordinate(500,500,0));
		arrived[500][500]=true;
		while(!q.isEmpty()){
			Coordinate c=q.poll();
			if(c.x==x&&c.y==y){
				System.out.println("YES");
				return;
			}
			if(c.n==3)continue;
			for(int i=0;i<8;i++){
				int nx=c.x+dx[i];
				int ny=c.y+dy[i];
				if(arrived[ny][nx])continue;
				arrived[ny][nx]=true;
				q.add(new Coordinate(nx, ny,c.n+1));
			}
		}
		System.out.println("NO");
	}
	class Coordinate{
		int x,y,n;
		public Coordinate(int x,int y,int n) {
			this.x=x;this.y=y;this.n=n;
		}
	}
}
0