結果
問題 |
No.240 ナイト散歩
|
ユーザー |
|
提出日時 | 2020-03-19 16:20:26 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 628 bytes |
コンパイル時間 | 3,695 ms |
コンパイル使用メモリ | 77,264 KB |
実行使用メモリ | 41,624 KB |
最終ジャッジ日時 | 2024-12-14 03:17:19 |
合計ジャッジ時間 | 9,252 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.*; import java.io.*; import java.math.*; public class No240 { public static String ans = "NO"; public static int X; public static int Y; public static void main(String[] args) { Scanner sc = new Scanner(System.in); X = sc.nextInt(); Y = sc.nextInt(); bfs(0, 0, 0); System.out.println(ans); } public static void bfs(int x, int y, int c) { if(c > 3) return; if(x == X && y == Y) { ans = "YES"; return; } bfs(x-2, y-1 ,c+1); bfs(x-2, y+1 ,c+1); bfs(x-1, y-2 ,c+1); bfs(x-1, y+2 ,c+1); bfs(x+1, y-2 ,c+1); bfs(x+1, y+2 ,c+1); bfs(x+2, y-1 ,c+1); bfs(x+2, y+1 ,c+1); } }