結果

問題 No.240 ナイト散歩
ユーザー shinwisteriashinwisteria
提出日時 2017-04-01 16:38:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 3,790 ms
コンパイル使用メモリ 78,900 KB
実行使用メモリ 41,616 KB
最終ジャッジ日時 2024-04-16 19:46:54
合計ジャッジ時間 9,466 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
41,204 KB
testcase_01 AC 137 ms
41,180 KB
testcase_02 AC 137 ms
41,192 KB
testcase_03 AC 137 ms
41,180 KB
testcase_04 AC 138 ms
41,336 KB
testcase_05 AC 137 ms
41,448 KB
testcase_06 AC 138 ms
41,316 KB
testcase_07 AC 140 ms
41,480 KB
testcase_08 AC 138 ms
41,408 KB
testcase_09 AC 143 ms
41,480 KB
testcase_10 AC 139 ms
41,540 KB
testcase_11 AC 139 ms
40,920 KB
testcase_12 AC 137 ms
41,492 KB
testcase_13 AC 126 ms
40,248 KB
testcase_14 AC 135 ms
41,192 KB
testcase_15 AC 135 ms
41,468 KB
testcase_16 AC 138 ms
41,556 KB
testcase_17 AC 130 ms
39,764 KB
testcase_18 AC 138 ms
41,300 KB
testcase_19 AC 135 ms
41,480 KB
testcase_20 AC 138 ms
41,328 KB
testcase_21 AC 139 ms
41,164 KB
testcase_22 AC 136 ms
41,400 KB
testcase_23 AC 135 ms
41,088 KB
testcase_24 AC 137 ms
41,332 KB
testcase_25 AC 140 ms
41,244 KB
testcase_26 AC 139 ms
41,360 KB
testcase_27 AC 134 ms
40,928 KB
testcase_28 AC 138 ms
41,336 KB
testcase_29 AC 138 ms
41,616 KB
testcase_30 AC 139 ms
41,336 KB
testcase_31 AC 138 ms
41,112 KB
testcase_32 AC 124 ms
40,052 KB
testcase_33 AC 136 ms
41,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;
public class Knightwalk {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		int X = s.nextInt(),Y = s.nextInt();
		ArrayList<Integer> x = new ArrayList<>();
		ArrayList<Integer> y = new ArrayList<>();
		x.add(0);
		y.add(0);
		ArrayDeque<Integer> z = new ArrayDeque<>();
		ArrayDeque<Integer> keep = new ArrayDeque<>();
		z.offer(0); 
		z.offer(0);
		int[] roota = new int[]{1,1,2,2,-1,-1,-2,-2};
		int[] rootb = new int[]{2,-2,1,-1,2,-2,1,-1};
		
		s.close();
		for(int i = 1;i <= 3;i++){
			while(!z.isEmpty()){
				int nowx = z.poll();
				int nowy = z.poll();
				for(int j = 0;j < 8;j++){
					//System.out.println(roota[j] + "  " + rootb[j]);
					x.add(nowx+roota[j]);
					keep.offer(nowx+roota[j]);
					y.add(nowy + rootb[j]);
					keep.offer(nowy + rootb[j]);
				}
			}
			z.addAll(keep);
			keep.clear();
		}
		//System.out.println(x);
		//System.out.println(y);
		if(X > 6 || Y > 6 || X < -6 || Y < -6){
			System.out.println("NO");
		}else{
			while(x.contains(X)){
				int p = x.indexOf(X);
				if(y.get(p) == Y){
					System.out.println("YES");
					break;
				}else{
					x.remove(p);
					y.remove(p);
				}
			}
			if(!x.contains(X)){
				System.out.println("NO");
			}
		}

	}

}
0