結果

問題 No.3 ビットすごろく
ユーザー yun_appyun_app
提出日時 2016-05-10 19:59:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,381 ms / 5,000 ms
コード長 1,253 bytes
コンパイル時間 2,670 ms
コンパイル使用メモリ 75,124 KB
実行使用メモリ 63,704 KB
最終ジャッジ日時 2023-09-13 23:52:43
合計ジャッジ時間 19,347 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,392 KB
testcase_01 AC 46 ms
49,084 KB
testcase_02 AC 47 ms
49,344 KB
testcase_03 AC 94 ms
54,648 KB
testcase_04 AC 80 ms
51,588 KB
testcase_05 AC 248 ms
61,532 KB
testcase_06 AC 100 ms
56,244 KB
testcase_07 AC 87 ms
54,208 KB
testcase_08 AC 177 ms
58,388 KB
testcase_09 AC 522 ms
63,704 KB
testcase_10 AC 750 ms
62,720 KB
testcase_11 AC 462 ms
63,292 KB
testcase_12 AC 205 ms
60,008 KB
testcase_13 AC 90 ms
55,244 KB
testcase_14 AC 674 ms
62,820 KB
testcase_15 AC 1,248 ms
62,908 KB
testcase_16 AC 860 ms
63,672 KB
testcase_17 AC 1,159 ms
63,216 KB
testcase_18 AC 89 ms
54,688 KB
testcase_19 AC 1,371 ms
63,336 KB
testcase_20 AC 65 ms
51,156 KB
testcase_21 AC 46 ms
49,160 KB
testcase_22 AC 698 ms
63,140 KB
testcase_23 AC 1,381 ms
61,528 KB
testcase_24 AC 1,359 ms
63,340 KB
testcase_25 AC 1,237 ms
63,080 KB
testcase_26 AC 44 ms
49,224 KB
testcase_27 AC 91 ms
54,524 KB
testcase_28 AC 793 ms
62,896 KB
testcase_29 AC 451 ms
63,168 KB
testcase_30 AC 47 ms
50,168 KB
testcase_31 AC 48 ms
50,444 KB
testcase_32 AC 419 ms
62,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<Integer> list = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            list.add(Integer.bitCount(i+1));
        }
        calc(list,0,n,1);
        System.out.println(map.containsKey(n-1)?map.get(n-1):"-1");
    }
    
    static HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
    public static void calc(ArrayList<Integer> list,int start,int goal,int step){
        if(start<0 || start>=goal){
            return;
        }
        if(map.containsKey(start)&&map.get(start) < step){
            return;
        }
        map.put(start,step);
        if(start==goal){
            return;
        }
        int n = list.get(start);
        if(n>0){
            calc(list,start+n,goal,step+1);
            calc(list,start-n,goal,step+1);
        }
        return;
    }
}
0