結果
問題 | No.3 ビットすごろく |
ユーザー | yuki2006 |
提出日時 | 2014-09-30 02:29:40 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,469 bytes |
コンパイル時間 | 1,979 ms |
コンパイル使用メモリ | 74,896 KB |
実行使用メモリ | 58,620 KB |
最終ジャッジ日時 | 2023-08-28 19:55:46 |
合計ジャッジ時間 | 7,159 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
56,348 KB |
testcase_01 | AC | 115 ms
56,048 KB |
testcase_02 | AC | 116 ms
58,272 KB |
testcase_03 | AC | 119 ms
56,136 KB |
testcase_04 | AC | 116 ms
56,052 KB |
testcase_05 | AC | 123 ms
55,704 KB |
testcase_06 | AC | 120 ms
55,888 KB |
testcase_07 | AC | 117 ms
55,904 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 124 ms
55,728 KB |
testcase_13 | AC | 118 ms
56,032 KB |
testcase_14 | AC | 126 ms
56,008 KB |
testcase_15 | AC | 125 ms
56,160 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 118 ms
55,768 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 117 ms
56,468 KB |
testcase_22 | AC | 126 ms
58,620 KB |
testcase_23 | AC | 126 ms
56,556 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 115 ms
56,732 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 116 ms
56,040 KB |
testcase_32 | WA | - |
ソースコード
import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); boolean[] check = new boolean[N + 1]; System.out.println(bfs(N, check)); } public static class Tuple { public int a; public int b; Tuple(int a, int b) { this.a = a; this.b = b; } } private static int bfs(int n, boolean[] check) { LinkedList<Tuple> queue = new LinkedList<>(); queue.add(new Tuple(1, 1)); check[1] = true; while (queue.size() > 0) { Tuple v = queue.pop(); if (v.a == n) { return v.b; } int bitCount = getBitCount(v.a); int a = v.a - bitCount; int b = v.a + bitCount; if (a > 0) { if (!check[a]) { check[a] = true; queue.push(new Tuple(a, v.b + 1)); } } if (b <= n) { if (!check[b]) { queue.push(new Tuple(b, v.b + 1)); } } } return -1; } static int getBitCount(int n) { int count; for (count = 0; n > 0; count++) { n = n & (n - 1); } return count; } }