結果

問題 No.3 ビットすごろく
ユーザー IceEijiIceEiji
提出日時 2019-03-21 18:34:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 75,196 KB
実行使用メモリ 57,756 KB
最終ジャッジ日時 2023-10-19 05:29:06
合計ジャッジ時間 8,329 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,836 KB
testcase_01 AC 135 ms
57,428 KB
testcase_02 AC 134 ms
55,744 KB
testcase_03 AC 136 ms
57,144 KB
testcase_04 AC 134 ms
57,620 KB
testcase_05 AC 141 ms
57,756 KB
testcase_06 AC 139 ms
57,612 KB
testcase_07 AC 139 ms
57,500 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 139 ms
57,440 KB
testcase_13 AC 140 ms
57,300 KB
testcase_14 AC 138 ms
57,396 KB
testcase_15 AC 139 ms
57,596 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 143 ms
57,252 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 140 ms
57,432 KB
testcase_22 AC 140 ms
57,640 KB
testcase_23 AC 141 ms
57,436 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 138 ms
57,564 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class BitSugoroku {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> root = new ArrayList<Integer>();
        for (int i = 1; i < n;) {
            int mv = Integer.bitCount(i);
            int go = i + mv;
            int back = i - mv;
            if (go <= n) {
                i = go;
                root.add(go);
            } else {
                if (root.contains(back)) {
                    root.clear();
                    break;
                }
                i = back;
                root.add(back);
            }
        }
        System.out.println(root.size() != 0 ? root.size() + 1 : -1);
    }
}
0