結果
問題 | No.3 ビットすごろく |
ユーザー | muston |
提出日時 | 2016-05-17 17:16:01 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 2,507 bytes |
コンパイル時間 | 2,163 ms |
コンパイル使用メモリ | 74,264 KB |
実行使用メモリ | 56,200 KB |
最終ジャッジ日時 | 2023-09-13 23:56:26 |
合計ジャッジ時間 | 8,001 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
55,936 KB |
testcase_01 | AC | 130 ms
55,792 KB |
testcase_02 | AC | 129 ms
55,804 KB |
testcase_03 | AC | 130 ms
56,104 KB |
testcase_04 | AC | 133 ms
55,780 KB |
testcase_05 | AC | 132 ms
56,040 KB |
testcase_06 | AC | 131 ms
55,836 KB |
testcase_07 | AC | 132 ms
55,888 KB |
testcase_08 | AC | 132 ms
55,796 KB |
testcase_09 | AC | 128 ms
53,748 KB |
testcase_10 | AC | 129 ms
55,784 KB |
testcase_11 | AC | 130 ms
56,200 KB |
testcase_12 | AC | 131 ms
55,884 KB |
testcase_13 | AC | 132 ms
56,032 KB |
testcase_14 | AC | 131 ms
55,852 KB |
testcase_15 | AC | 134 ms
55,668 KB |
testcase_16 | AC | 131 ms
55,860 KB |
testcase_17 | AC | 130 ms
55,780 KB |
testcase_18 | AC | 130 ms
55,740 KB |
testcase_19 | AC | 134 ms
55,748 KB |
testcase_20 | AC | 128 ms
55,940 KB |
testcase_21 | AC | 131 ms
56,132 KB |
testcase_22 | AC | 131 ms
55,744 KB |
testcase_23 | AC | 131 ms
56,180 KB |
testcase_24 | AC | 131 ms
55,860 KB |
testcase_25 | AC | 130 ms
55,980 KB |
testcase_26 | AC | 128 ms
55,776 KB |
testcase_27 | AC | 138 ms
55,772 KB |
testcase_28 | AC | 137 ms
55,744 KB |
testcase_29 | AC | 134 ms
55,572 KB |
testcase_30 | AC | 128 ms
55,844 KB |
testcase_31 | AC | 129 ms
55,672 KB |
testcase_32 | AC | 131 ms
55,748 KB |
ソースコード
import java.io.*; import java.util.*; /*yukicoder No.3 ビットすごろく*/ class No3{ public static void main(String[] args){ final int NUMBER = 0; final int COST =1; Scanner scan = new Scanner(System.in); //ゴールまでのマスnを入力 int n = scan.nextInt(); int[] log = new int[10000]; int[][] route = new int[10000][2]; //道を記憶 int i=0; // int t=0; route[i][NUMBER] =1; route[i][COST] = 1; log[i] = 1; //System.out.printf("DBG>> Star\n"); boolean isEnd = false; while (!isEnd){ //移動量を出す(今のマス数を2進数にしたときの1の数) int move = Integer.bitCount(route[i][NUMBER]); //後退するマスを出す int val = route[i][NUMBER] - move; if(0 < val&&log[val-1]==0){ route[t+1][COST] = route[i][COST]+1; route[t+1][NUMBER] = val; log[route[t+1][NUMBER]-1] =1; t++; if(route[t][NUMBER] == n) isEnd = true; } //前進するマスを出す val = route[i][NUMBER] + move; if(val<=n&&log[val-1]==0){ route[t+1][COST] = route[i][COST]+1; route[t+1][NUMBER] = val; log[route[t+1][NUMBER]-1] =1; t++; if(route[t][NUMBER] == n) isEnd = true; } i++; if(t<i) isEnd = true; } //System.out.printf("DBG>> Ref\n"); // for(int k=0;k<2;k++){ // for(int l=0;l<=t;l++) { // System.out.printf(" %2d", route[l][k]); // } // System.out.println(""); // } // for(int k=0;k<n;k++) // System.out.printf(" %d",log[k]); //System.out.printf("\nDBG>> End\n"); if(t<i&&1<n) System.out.println(-1); else System.out.println(route[t][COST]); /* for(int i = 0; i < n; i++) route[i] = i+1; while(n!=here){ move = Integer.bitCount(here); //今のマス数を2進数にしたときの1の数 if(log[here-1]-move==0&&here>1){ here = route[here-1] - move; log[here-1] = 1; System.out.println(here); }else if(here+move<n){ here = route[here-1] + move; log[here-1] = 1; System.out.println(here); }else{ count = -1; break; } count++; //ゴールマスに止まったらループから抜ける if(log[n-1] == 1) break; } //ゴールまでの移動回数を出力 System.out.println(count); /* */ } }