結果

問題 No.240 ナイト散歩
ユーザー kuramukuramu
提出日時 2016-01-30 22:52:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 77,664 KB
実行使用メモリ 37,280 KB
最終ジャッジ日時 2024-04-16 19:40:05
合計ジャッジ時間 4,730 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,236 KB
testcase_01 AC 52 ms
36,984 KB
testcase_02 AC 50 ms
37,216 KB
testcase_03 AC 51 ms
36,888 KB
testcase_04 AC 53 ms
37,052 KB
testcase_05 AC 53 ms
36,820 KB
testcase_06 AC 52 ms
36,964 KB
testcase_07 AC 52 ms
37,040 KB
testcase_08 AC 52 ms
37,156 KB
testcase_09 AC 54 ms
36,948 KB
testcase_10 AC 52 ms
37,052 KB
testcase_11 AC 52 ms
37,128 KB
testcase_12 AC 53 ms
37,000 KB
testcase_13 AC 52 ms
37,188 KB
testcase_14 AC 51 ms
37,160 KB
testcase_15 AC 52 ms
37,188 KB
testcase_16 AC 53 ms
37,100 KB
testcase_17 AC 52 ms
37,104 KB
testcase_18 AC 53 ms
37,096 KB
testcase_19 AC 54 ms
36,788 KB
testcase_20 AC 52 ms
37,232 KB
testcase_21 AC 53 ms
36,908 KB
testcase_22 AC 52 ms
37,208 KB
testcase_23 AC 52 ms
37,040 KB
testcase_24 AC 52 ms
36,804 KB
testcase_25 AC 53 ms
36,996 KB
testcase_26 AC 53 ms
37,136 KB
testcase_27 AC 52 ms
37,084 KB
testcase_28 AC 53 ms
36,680 KB
testcase_29 AC 53 ms
36,552 KB
testcase_30 AC 53 ms
36,840 KB
testcase_31 AC 53 ms
37,280 KB
testcase_32 AC 54 ms
37,052 KB
testcase_33 AC 52 ms
36,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	 static boolean[][] dp;
	 static boolean[][] memo;
	 public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	  String[] temp = stdReader.readLine().split(" ");
	    	  int X = Integer.parseInt(temp[0]);
	    	  int Y = Integer.parseInt(temp[1]);
	    	  if(Math.abs(X)>6 || Math.abs(Y)>6){
	    		  System.out.println("NO");
	    		  return;
	    	  }
	    	  dp = new boolean[13][13];
	    	  memo = new boolean[13][13];
	    	  int[] dx = {-2,-2,-1,-1,1,1,2,2};
	    	  int[] dy = {-1,1,-2,2,-2,2,-1,1};
	    	  dp[6][6] = true;
	    	  memo[6][6] = true;
	    	  for(int i=0;i<3;i++){
	    		  setKnight(dx, dy);
	    	  }
	    	  System.out.println(dp[X+6][Y+6]?"YES":"NO");
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
	 
	 public static void setKnight(int[] dx, int[] dy){
		for(int i=0;i<13;i++){
			for(int j=0;j<13;j++){
				if(dp[i][j] && memo[i][j]){
					for(int k=0;k<8;k++){
						dp[i+dx[k]][j+dy[k]] = true;
					}
				}
			}
		}  		  
 		 for(int i=0;i<13;i++){
 	   		  for(int j=0;j<13;j++){
 	   			  if(dp[i][j] && !memo[i][j]) memo[i][j] = true;		  
 	   		  }  		  
 		 }
	 } 
}
0