結果

問題 No.3 ビットすごろく
ユーザー hj5ln8kbDM8t2fFhj5ln8kbDM8t2fF
提出日時 2019-06-26 23:08:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,798 bytes
コンパイル時間 3,284 ms
コンパイル使用メモリ 73,668 KB
実行使用メモリ 63,180 KB
最終ジャッジ日時 2023-09-08 13:12:27
合計ジャッジ時間 13,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,812 KB
testcase_01 AC 126 ms
55,768 KB
testcase_02 AC 126 ms
56,152 KB
testcase_03 AC 127 ms
55,788 KB
testcase_04 WA -
testcase_05 AC 127 ms
53,504 KB
testcase_06 AC 126 ms
55,580 KB
testcase_07 AC 125 ms
55,852 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
56,064 KB
testcase_13 AC 125 ms
55,724 KB
testcase_14 AC 127 ms
56,232 KB
testcase_15 AC 127 ms
55,520 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 132 ms
55,680 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 127 ms
55,644 KB
testcase_22 AC 128 ms
55,976 KB
testcase_23 AC 128 ms
55,628 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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 num = 1;
        int ichi = 0;
        int t_kekka = 0;
        int h_kekka = 0;
        int flag = 0;
        int kaisu = 1;
        
        while(flag<2){
            kaisu = kaisu + 1;
            Kazu kz = new Kazu();
            ichi = kz.program1(num);
            
            Tasu ts = new Tasu();
            t_kekka = ts.program2(num,ichi);
            
            if(t_kekka==N){
                break;
            }else if(t_kekka>N){
                flag = flag + 1;
                Hiku hk = new Hiku();
                h_kekka = hk.program3(num,ichi);
                num = h_kekka;
                if(flag==2){
                    kaisu = -1;
                }
            }else if(t_kekka<N){
                num = t_kekka;
            }
    }
    System.out.println(kaisu);
    }
}
0