結果
問題 | No.3 ビットすごろく |
ユーザー | yuki2006 |
提出日時 | 2014-09-30 03:13:16 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,512 bytes |
コンパイル時間 | 2,014 ms |
コンパイル使用メモリ | 75,128 KB |
実行使用メモリ | 56,892 KB |
最終ジャッジ日時 | 2023-08-28 19:54:54 |
合計ジャッジ時間 | 7,458 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
55,992 KB |
testcase_01 | AC | 119 ms
56,044 KB |
testcase_02 | AC | 117 ms
55,860 KB |
testcase_03 | AC | 128 ms
55,848 KB |
testcase_04 | AC | 126 ms
55,796 KB |
testcase_05 | AC | 128 ms
55,816 KB |
testcase_06 | AC | 129 ms
55,812 KB |
testcase_07 | AC | 128 ms
56,100 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 119 ms
56,144 KB |
testcase_13 | AC | 119 ms
56,180 KB |
testcase_14 | AC | 122 ms
55,788 KB |
testcase_15 | AC | 127 ms
56,204 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 121 ms
56,156 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 122 ms
55,852 KB |
testcase_22 | AC | 126 ms
55,744 KB |
testcase_23 | AC | 126 ms
56,172 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 117 ms
56,132 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 118 ms
55,668 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.pollFirst(); 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]) { check[b] = true; 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; } }