結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  kohaku_kohaku | 
| 提出日時 | 2016-12-03 18:45:53 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 833 bytes | 
| コンパイル時間 | 2,522 ms | 
| コンパイル使用メモリ | 77,364 KB | 
| 実行使用メモリ | 54,372 KB | 
| 最終ジャッジ日時 | 2024-12-17 19:28:47 | 
| 合計ジャッジ時間 | 7,453 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 31 WA * 2 | 
ソースコード
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;
    }
}
            
            
            
        