結果
問題 | No.3 ビットすごろく |
ユーザー | yuki2006 |
提出日時 | 2015-05-31 17:46:03 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,527 bytes |
コンパイル時間 | 3,400 ms |
コンパイル使用メモリ | 76,184 KB |
実行使用メモリ | 103,544 KB |
最終ジャッジ日時 | 2023-09-20 18:06:30 |
合計ジャッジ時間 | 17,202 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,612 KB |
testcase_01 | AC | 125 ms
55,400 KB |
testcase_02 | AC | 126 ms
55,916 KB |
testcase_03 | AC | 194 ms
59,380 KB |
testcase_04 | AC | 145 ms
57,804 KB |
testcase_05 | AC | 491 ms
68,712 KB |
testcase_06 | AC | 195 ms
59,300 KB |
testcase_07 | AC | 185 ms
59,576 KB |
testcase_08 | AC | 256 ms
61,832 KB |
testcase_09 | AC | 3,128 ms
103,544 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Yuki003 { int bitCount(int value) { int count = 0; while (value > 0) { count += value % 2; value /= 2; } return count; } Yuki003() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); System.out.println(search(N)); } private int search(final int N) { boolean[] visit = new boolean[N + 1]; ArrayList<Integer> list = new ArrayList<>(); list.add(1); int move = 1; visit[1] = true; while (list.size() > 0) { ArrayList<Integer> next = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { final Integer value = list.get(i); if (value == N) { return move; } int bit = bitCount(value); int prev = value - bit; int nxt = value + bit; if (1 <= prev && !visit[prev]) { next.add(prev); visit[value] = true; } if (nxt <= N && !visit[nxt]) { next.add(nxt); visit[value] = true; } } list = next; move++; } return -1; } public static void main(String[] args) { new Yuki003(); } }