結果

問題 No.240 ナイト散歩
ユーザー 37zigen37zigen
提出日時 2016-05-01 16:03:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 77,632 KB
実行使用メモリ 42,892 KB
最終ジャッジ日時 2024-04-16 19:41:38
合計ジャッジ時間 8,048 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
42,676 KB
testcase_01 AC 135 ms
42,388 KB
testcase_02 AC 133 ms
42,652 KB
testcase_03 AC 137 ms
42,396 KB
testcase_04 AC 140 ms
42,448 KB
testcase_05 AC 136 ms
42,536 KB
testcase_06 AC 135 ms
42,540 KB
testcase_07 AC 135 ms
42,716 KB
testcase_08 AC 136 ms
42,556 KB
testcase_09 AC 135 ms
42,604 KB
testcase_10 AC 137 ms
42,476 KB
testcase_11 AC 137 ms
42,772 KB
testcase_12 AC 137 ms
42,596 KB
testcase_13 AC 138 ms
42,332 KB
testcase_14 AC 134 ms
42,612 KB
testcase_15 AC 137 ms
42,892 KB
testcase_16 AC 137 ms
42,332 KB
testcase_17 AC 138 ms
42,440 KB
testcase_18 AC 139 ms
42,172 KB
testcase_19 AC 135 ms
42,696 KB
testcase_20 AC 137 ms
42,360 KB
testcase_21 AC 136 ms
42,548 KB
testcase_22 AC 135 ms
42,324 KB
testcase_23 AC 137 ms
42,184 KB
testcase_24 AC 137 ms
42,784 KB
testcase_25 AC 136 ms
42,664 KB
testcase_26 AC 135 ms
42,404 KB
testcase_27 AC 133 ms
42,220 KB
testcase_28 AC 136 ms
42,688 KB
testcase_29 AC 134 ms
42,328 KB
testcase_30 AC 138 ms
42,472 KB
testcase_31 AC 138 ms
42,584 KB
testcase_32 AC 136 ms
42,412 KB
testcase_33 AC 135 ms
42,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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