結果
問題 | No.3 ビットすごろく |
ユーザー | mikan765 |
提出日時 | 2017-07-05 13:18:05 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 698 bytes |
コンパイル時間 | 2,430 ms |
コンパイル使用メモリ | 76,832 KB |
実行使用メモリ | 56,384 KB |
最終ジャッジ日時 | 2024-04-15 18:11:00 |
合計ジャッジ時間 | 7,061 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 123 ms
54,188 KB |
testcase_01 | AC | 122 ms
53,800 KB |
testcase_02 | AC | 128 ms
54,260 KB |
testcase_03 | AC | 129 ms
54,196 KB |
testcase_04 | AC | 127 ms
54,072 KB |
testcase_05 | AC | 140 ms
54,212 KB |
testcase_06 | AC | 121 ms
54,068 KB |
testcase_07 | AC | 125 ms
53,916 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 141 ms
54,696 KB |
testcase_13 | AC | 122 ms
56,384 KB |
testcase_14 | AC | 117 ms
53,428 KB |
testcase_15 | AC | 112 ms
53,420 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 124 ms
54,452 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 115 ms
52,916 KB |
testcase_22 | AC | 131 ms
54,308 KB |
testcase_23 | AC | 128 ms
54,688 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 126 ms
54,108 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 127 ms
54,180 KB |
testcase_32 | WA | - |
ソースコード
import java.util.*; import java.util.Arrays; public class Main { static int[] isOk = new int[10000]; static int n; public static void main(String[] args){ Arrays.fill(isOk, 0); Scanner sc = new Scanner(System.in); n = sc.nextInt(); isOk[0] = 1; check(1); if(isOk[n-1]==0){ System.out.println(-1); }else{ System.out.println(isOk[n-1]); } } static void check(int x){ int sum = 0; int xx = x; do{ sum += xx%2; xx = xx/2; }while(xx>0); if(x+sum<=n){ if(isOk[x+sum-1]==0){ isOk[x+sum-1]=isOk[x-1]+1; check(x+sum); } } if(x-sum>0){ if(isOk[x-sum-1]==0){ isOk[x-sum-1]=isOk[x-1]+1; check(x-sum); } } } }