結果
問題 | No.3 ビットすごろく |
ユーザー | hj5ln8kbDM8t2fF |
提出日時 | 2019-06-26 20:51:46 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,799 bytes |
コンパイル時間 | 2,030 ms |
コンパイル使用メモリ | 73,692 KB |
実行使用メモリ | 114,076 KB |
最終ジャッジ日時 | 2023-09-08 09:02:15 |
合計ジャッジ時間 | 12,842 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 122 ms
55,968 KB |
testcase_03 | AC | 122 ms
55,824 KB |
testcase_04 | WA | - |
testcase_05 | AC | 124 ms
55,560 KB |
testcase_06 | AC | 122 ms
55,856 KB |
testcase_07 | WA | - |
testcase_08 | AC | 120 ms
56,064 KB |
testcase_09 | AC | 119 ms
55,572 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 124 ms
55,864 KB |
testcase_13 | AC | 130 ms
55,892 KB |
testcase_14 | AC | 128 ms
55,764 KB |
testcase_15 | AC | 120 ms
56,428 KB |
testcase_16 | AC | 119 ms
55,836 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 118 ms
56,228 KB |
testcase_23 | AC | 117 ms
53,864 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | TLE | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
//★★★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 = 0; 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); } }