結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2015-07-16 19:33:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 838 bytes |
コンパイル時間 | 2,295 ms |
コンパイル使用メモリ | 77,948 KB |
実行使用メモリ | 54,376 KB |
最終ジャッジ日時 | 2024-10-07 20:58:15 |
合計ジャッジ時間 | 7,363 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int[] dx = {-2,-2,-1,-1,1,1,2,2};int[] dy = {-1,1,-2,2,-2,2,-1,1};Queue<Integer> xque = new LinkedList<>();Queue<Integer> yque = new LinkedList<>();int X = sc.nextInt();int Y = sc.nextInt();if(X==0 && Y == 0){System.out.println("YES");return;}xque.add(0);yque.add(0);for(int i=0;i<3;i++){int len = xque.size();for(int j=0;j<len;j++){int nowx = xque.poll();int nowy = yque.poll();for(int k=0;k<dx.length;k++){int nextx = nowx + dx[k];int nexty = nowy + dy[k];if(X == nextx && Y == nexty){System.out.println("YES");return;}xque.add(nextx);yque.add(nexty);}}}System.out.println("NO");}}