結果

問題 No.240 ナイト散歩
ユーザー darknight
提出日時 2016-11-23 01:46:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 4,276 ms
コンパイル使用メモリ 79,492 KB
実行使用メモリ 54,544 KB
最終ジャッジ日時 2024-10-07 21:32:41
合計ジャッジ時間 7,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
public class Main {
    
    //探索終了の条件
    static int X ;
    static int Y ;
    //探索する木
    static int a[] = {1,2,2,1,-1,-2,-2,-1};
    static int b[] = {2,1,-1,-2,-2,-1,1,2};
    
    	public static void main(String[] args) {
    	    Scanner sc  = new Scanner(System.in);
            X = Integer.parseInt(sc.next());
            Y = Integer.parseInt(sc.next());
        
            boolean ans = f(0,0,0);
        
            if(ans) System.out.print("YES");
            if(!ans)System.out.print("NO");
                System.out.println();
            }
            
        // p,q : 探索開始地点; depth : 探索回数
        static  boolean f (int p,int q,int depth){
            //System.out.println("p:"+p+" q:"+q);
            //目的の値に達する    
            if(p==X&&q==Y) return true;
            //s探索終了の条件
            if(depth==3)       return false;
            for(int i=0;i<8;i++)
            {
            //目的の値に達する
            if(f(p+a[i],q+b[i],depth+1)) return true;
            }
            //探索失敗
             return false;
        }
   
}
0