結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2018-03-26 22:28:13 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 639 bytes |
コンパイル時間 | 2,495 ms |
コンパイル使用メモリ | 77,452 KB |
実行使用メモリ | 54,316 KB |
最終ジャッジ日時 | 2024-06-25 12:12:13 |
合計ジャッジ時間 | 7,950 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import static java.lang.System.*;import java.util.*;public class Main {static Scanner sc = new Scanner(System.in);static int[] dy = {-1,0,1,0};static int[] dx = {0,1,0,-1};static int gx = sc.nextInt();static int gy = sc.nextInt();public static void main(String[] args) {out.println(dfs(0,0,0)?"YES":"NO");}static boolean dfs(int x, int y, int n) {if (n>3) return false;if (x==gx && y==gy) return true;return (dfs(x-2,y-1,n+1) ||dfs(x-2,y+1,n+1) ||dfs(x-1,y-2,n+1) ||dfs(x-1,y+2,n+1) ||dfs(x+1,y-2,n+1) ||dfs(x+1,y+2,n+1) ||dfs(x+2,y-1,n+1) ||dfs(x+2,y+1,n+1));}}