結果

問題 No.3 ビットすごろく
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-03 18:45:53
言語 Java19
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 833 bytes
コンパイル時間 4,344 ms
コンパイル使用メモリ 76,012 KB
実行使用メモリ 56,100 KB
最終ジャッジ日時 2023-08-22 18:43:40
合計ジャッジ時間 9,696 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,032 KB
testcase_01 AC 117 ms
55,712 KB
testcase_02 AC 118 ms
55,660 KB
testcase_03 AC 126 ms
55,916 KB
testcase_04 AC 125 ms
55,896 KB
testcase_05 AC 136 ms
55,752 KB
testcase_06 AC 130 ms
55,400 KB
testcase_07 AC 127 ms
56,032 KB
testcase_08 AC 129 ms
55,684 KB
testcase_09 AC 138 ms
55,996 KB
testcase_10 AC 142 ms
55,768 KB
testcase_11 AC 136 ms
55,604 KB
testcase_12 AC 134 ms
55,860 KB
testcase_13 AC 127 ms
55,704 KB
testcase_14 AC 142 ms
55,700 KB
testcase_15 AC 151 ms
55,760 KB
testcase_16 AC 151 ms
55,692 KB
testcase_17 AC 151 ms
56,032 KB
testcase_18 AC 126 ms
55,480 KB
testcase_19 AC 153 ms
55,996 KB
testcase_20 AC 121 ms
55,836 KB
testcase_21 AC 116 ms
55,660 KB
testcase_22 AC 140 ms
55,900 KB
testcase_23 AC 152 ms
55,720 KB
testcase_24 AC 152 ms
55,640 KB
testcase_25 AC 151 ms
56,100 KB
testcase_26 AC 117 ms
55,624 KB
testcase_27 AC 127 ms
55,708 KB
testcase_28 AC 147 ms
55,844 KB
testcase_29 AC 136 ms
55,888 KB
testcase_30 AC 118 ms
55,908 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] c = new int [N+1];
        for(int i=2; i<=N; i++){
            c[i]=10000;
        }
        for(int i=1; i<=N; i++){
            int t=Integer.bitCount(i);
            go(c,i,N);
            if(i-t>=1&&c[i-t]>c[i]+1){
                c[i-t]=c[i]+1;
                go(c,i-t,N);
            }
        }
        int ans=-1;
        if(c[N]!=10000){
            ans=c[N]+1;
        }
        System.out.println(ans);
    }
    static int[] go(int []a, int i, int N){
        int t=Integer.bitCount(i);
        while(i+t<=N){
            a[i+t]=Math.min(a[i+t],a[i]+1);
            i=i+t;
            t=Integer.bitCount(i);
        }
        return a;
    }
}
0