結果
問題 | No.3 ビットすごろく |
ユーザー | spring |
提出日時 | 2019-06-13 16:31:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 175 ms / 5,000 ms |
コード長 | 1,332 bytes |
コンパイル時間 | 2,904 ms |
コンパイル使用メモリ | 74,788 KB |
実行使用メモリ | 58,836 KB |
最終ジャッジ日時 | 2023-09-14 01:20:30 |
合計ジャッジ時間 | 8,627 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
56,052 KB |
testcase_01 | AC | 122 ms
54,512 KB |
testcase_02 | AC | 122 ms
55,960 KB |
testcase_03 | AC | 146 ms
56,060 KB |
testcase_04 | AC | 132 ms
55,768 KB |
testcase_05 | AC | 152 ms
56,228 KB |
testcase_06 | AC | 150 ms
56,368 KB |
testcase_07 | AC | 134 ms
56,152 KB |
testcase_08 | AC | 151 ms
56,228 KB |
testcase_09 | AC | 155 ms
58,640 KB |
testcase_10 | AC | 159 ms
58,684 KB |
testcase_11 | AC | 154 ms
57,944 KB |
testcase_12 | AC | 150 ms
56,244 KB |
testcase_13 | AC | 144 ms
56,392 KB |
testcase_14 | AC | 155 ms
57,852 KB |
testcase_15 | AC | 175 ms
58,836 KB |
testcase_16 | AC | 171 ms
58,112 KB |
testcase_17 | AC | 159 ms
58,112 KB |
testcase_18 | AC | 157 ms
56,112 KB |
testcase_19 | AC | 161 ms
58,236 KB |
testcase_20 | AC | 129 ms
56,384 KB |
testcase_21 | AC | 122 ms
53,876 KB |
testcase_22 | AC | 151 ms
57,816 KB |
testcase_23 | AC | 162 ms
58,716 KB |
testcase_24 | AC | 152 ms
58,096 KB |
testcase_25 | AC | 165 ms
58,356 KB |
testcase_26 | AC | 122 ms
55,672 KB |
testcase_27 | AC | 141 ms
55,796 KB |
testcase_28 | AC | 157 ms
58,128 KB |
testcase_29 | AC | 146 ms
55,928 KB |
testcase_30 | AC | 124 ms
56,664 KB |
testcase_31 | AC | 125 ms
55,488 KB |
testcase_32 | AC | 164 ms
55,944 KB |
ソースコード
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); sc.close(); int[] list = new int[N+10]; int count = 1; int i=0; ArrayList<Integer> toDo = new ArrayList<Integer>(); ArrayList<Integer> queue= new ArrayList<Integer>(); toDo.add(1); list[1] = 1; while(i<1){ toDo.addAll(queue); queue.clear(); count+= 1; for(int searchNum : toDo){ String two = Integer.toBinaryString(searchNum); two = two.replace("0", ""); int change = two.length(); if(searchNum-change>0){ if(list[searchNum-change]==0){ list[searchNum-change]=count; queue.add(searchNum-change); }else{ list[searchNum-change]=Math.min(list[searchNum-change], count); } } if(searchNum+change<=N){ if(list[searchNum+change]==0){ list[searchNum+change]=count; queue.add(searchNum+change); }else{ list[searchNum+change]=Math.min(list[searchNum+change], count); } } if(list[N]!=0){ break; } } toDo.clear(); if(list[N]!=0){ System.out.println(list[N]); i+=1; break; } if(queue.isEmpty()&&toDo.isEmpty()){ System.out.println(-1); i+=1; break; } } }// mainmethod } // class