結果

問題 No.3 ビットすごろく
ユーザー hj5ln8kbDM8t2fFhj5ln8kbDM8t2fF
提出日時 2019-06-30 11:22:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,293 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 73,744 KB
実行使用メモリ 56,352 KB
最終ジャッジ日時 2023-09-19 06:38:29
合計ジャッジ時間 7,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,692 KB
testcase_01 WA -
testcase_02 AC 125 ms
55,768 KB
testcase_03 AC 126 ms
55,684 KB
testcase_04 WA -
testcase_05 AC 126 ms
55,816 KB
testcase_06 AC 125 ms
55,972 KB
testcase_07 AC 124 ms
55,784 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
55,816 KB
testcase_13 AC 124 ms
55,936 KB
testcase_14 AC 125 ms
55,904 KB
testcase_15 AC 126 ms
55,840 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 126 ms
55,840 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 126 ms
55,776 KB
testcase_22 AC 128 ms
55,720 KB
testcase_23 AC 129 ms
55,868 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 123 ms
55,808 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//★★★No.3 ビットすごろく★★★

//1
import java.util.*;

//数字の二進数の1の数を求めるクラス
//intは整数型なので、小数点以下は切り捨てられる
class Kazu{
    int ichi = 0;
    public int program1(int num){
        do{
            //numを2で割り切れなかった場合ichiの数を増やしていく
            if(num%2==1){
                ichi = ichi+1;
            }
            //numに2で割った後の数を入れる
            num = num/2;
        }while(num>0);
        return ichi;
    }
}

class Tasu{
    int t_kekka = 0;
    public int program2(int num,int ichi){
        t_kekka = num + ichi;
        return t_kekka;
    }
}

class Hiku{
    int h_kekka = 0;
    public int program3(int num,int ichi){
        h_kekka = num - ichi;
        return h_kekka;
    }
}

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int ichi = 0;        //今いる位置の1の数
        int ichi_p = 0;      //今いる位置の1回前にいた位置の1の数
//        int t_kekka = 1;
        int position = 1;    //今いる位置
        int position_p = 0;  //今いる位置の一回前にいた位置
//        int h_kekka = 0;
        int flag = 0;
        int kaisu = 1;      //移動した数
        
        while(flag<2){
            //今のpositionの1の数をえる
            Kazu kz = new Kazu();
            ichi_p = ichi;
            ichi = kz.program1(position);
            
            if(position==N){
                break;
            }else if(position>N){
                flag = flag + 1;
                Hiku hk = new Hiku();
                position = hk.program3(position_p,ichi_p);
                
                //移動回数を増やす
                kaisu = kaisu + 1;
                
                if(flag==2){
                    kaisu = -1;
                }
            }else if(position<N){
                Tasu ts = new Tasu();
                position_p = position;
                position = ts.program2(position,ichi);
                
                //移動回数を増やす
                kaisu = kaisu + 1;
            }
    }
    System.out.println(kaisu);
    }
}
0