結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kashiwagi513
                         | 
                    
| 提出日時 | 2019-02-20 00:35:32 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,167 bytes | 
| コンパイル時間 | 2,304 ms | 
| コンパイル使用メモリ | 79,160 KB | 
| 実行使用メモリ | 834,336 KB | 
| 最終ジャッジ日時 | 2024-10-13 06:46:04 | 
| 合計ジャッジ時間 | 14,908 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | MLE * 1 -- * 32 | 
ソースコード
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
    public static int getRange(int n, int acc){
        if(n==0){return acc;}
        else{return getRange(n/2, acc+(n%2));}
    }
    public static List<Integer> canReachTo(int max, int goal){
        List<Integer> ls = new ArrayList<Integer>();
        for(int i=1; i <= max; i++){
            int r = getRange(i, 0);
            if(i==goal+r && i <= max){ls.add(i);}
            if(i==goal-r && 1 <= i){ls.add(i);}
        }
        return ls;
    }
    public static int minPathTo(int max, int goal, int acc){
        List<Integer> ls = canReachTo(max, goal);
        List<Integer> temp = new ArrayList<Integer>();
        if(goal == 1){return acc;}
        for(Integer i : ls){
            int j = minPathTo(max, i.intValue(), acc+1);
            if(j != -1) { temp.add(j); }
        }
        if(temp.size() <= 0){return -1;}
        else{
            return Collections.min(temp);
        }
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        System.out.println(minPathTo(n, n, 0));
    }
}
            
            
            
        
            
kashiwagi513