結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2016-01-30 22:52:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 1,333 bytes |
コンパイル時間 | 2,489 ms |
コンパイル使用メモリ | 77,484 KB |
実行使用メモリ | 50,384 KB |
最終ジャッジ日時 | 2024-10-07 21:20:54 |
合計ジャッジ時間 | 5,030 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
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;}}}}