結果

問題 No.3 ビットすごろく
ユーザー yuki2006yuki2006
提出日時 2015-05-31 17:55:15
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,464 bytes
コンパイル時間 3,643 ms
コンパイル使用メモリ 76,004 KB
実行使用メモリ 190,004 KB
最終ジャッジ日時 2023-09-20 18:07:44
合計ジャッジ時間 12,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
60,508 KB
testcase_01 AC 124 ms
55,776 KB
testcase_02 AC 125 ms
56,164 KB
testcase_03 AC 184 ms
59,104 KB
testcase_04 AC 145 ms
57,964 KB
testcase_05 AC 714 ms
73,260 KB
testcase_06 AC 182 ms
58,700 KB
testcase_07 AC 172 ms
58,596 KB
testcase_08 AC 275 ms
67,532 KB
testcase_09 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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];
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        int move = 1;
        visit[1] = true;
        while (list.size() > 0) {
            LinkedList<Integer> next = new LinkedList<>();
            for (int value : list) {
                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();

    }
}
0