結果
問題 | No.3 ビットすごろく |
ユーザー | hj5ln8kbDM8t2fF |
提出日時 | 2019-06-30 11:26:10 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,296 bytes |
コンパイル時間 | 2,993 ms |
コンパイル使用メモリ | 73,340 KB |
実行使用メモリ | 57,772 KB |
最終ジャッジ日時 | 2023-09-19 06:42:40 |
合計ジャッジ時間 | 8,352 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
55,788 KB |
testcase_01 | AC | 126 ms
55,600 KB |
testcase_02 | AC | 129 ms
57,016 KB |
testcase_03 | AC | 133 ms
55,380 KB |
testcase_04 | WA | - |
testcase_05 | AC | 127 ms
55,576 KB |
testcase_06 | AC | 126 ms
55,536 KB |
testcase_07 | AC | 126 ms
55,764 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 127 ms
55,584 KB |
testcase_13 | AC | 127 ms
55,772 KB |
testcase_14 | AC | 127 ms
55,688 KB |
testcase_15 | AC | 127 ms
55,688 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 125 ms
55,804 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 130 ms
55,508 KB |
testcase_22 | AC | 129 ms
55,596 KB |
testcase_23 | AC | 127 ms
55,620 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 124 ms
55,568 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
ソースコード
//★★★No.3 ビットすごろく★★★ //v2 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); } }