結果

問題 No.240 ナイト散歩
ユーザー darknightdarknight
提出日時 2016-11-23 01:46:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 74,420 KB
実行使用メモリ 41,668 KB
最終ジャッジ日時 2024-04-16 19:44:48
合計ジャッジ時間 7,602 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,472 KB
testcase_01 AC 128 ms
41,600 KB
testcase_02 AC 126 ms
41,436 KB
testcase_03 AC 127 ms
41,464 KB
testcase_04 AC 128 ms
41,272 KB
testcase_05 AC 126 ms
41,196 KB
testcase_06 AC 127 ms
41,388 KB
testcase_07 AC 126 ms
41,540 KB
testcase_08 AC 129 ms
41,128 KB
testcase_09 AC 129 ms
41,512 KB
testcase_10 AC 128 ms
41,212 KB
testcase_11 AC 129 ms
41,436 KB
testcase_12 AC 128 ms
41,508 KB
testcase_13 AC 129 ms
41,268 KB
testcase_14 AC 127 ms
41,480 KB
testcase_15 AC 127 ms
41,244 KB
testcase_16 AC 130 ms
41,468 KB
testcase_17 AC 128 ms
41,504 KB
testcase_18 AC 129 ms
41,328 KB
testcase_19 AC 128 ms
41,120 KB
testcase_20 AC 125 ms
41,332 KB
testcase_21 AC 128 ms
41,488 KB
testcase_22 AC 130 ms
41,308 KB
testcase_23 AC 128 ms
41,100 KB
testcase_24 AC 130 ms
41,060 KB
testcase_25 AC 128 ms
41,264 KB
testcase_26 AC 128 ms
41,180 KB
testcase_27 AC 128 ms
41,144 KB
testcase_28 AC 128 ms
41,152 KB
testcase_29 AC 129 ms
41,276 KB
testcase_30 AC 128 ms
41,376 KB
testcase_31 AC 130 ms
41,668 KB
testcase_32 AC 128 ms
41,288 KB
testcase_33 AC 124 ms
41,364 KB
権限があれば一括ダウンロードができます

ソースコード

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