結果

問題 No.3 ビットすごろく
ユーザー n_gojon_gojo
提出日時 2020-04-10 18:08:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 3,402 ms
コンパイル使用メモリ 75,696 KB
実行使用メモリ 65,084 KB
最終ジャッジ日時 2023-10-13 10:11:02
合計ジャッジ時間 9,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,032 KB
testcase_01 AC 122 ms
56,256 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 126 ms
56,248 KB
testcase_05 WA -
testcase_06 AC 225 ms
62,600 KB
testcase_07 AC 132 ms
56,016 KB
testcase_08 AC 147 ms
55,692 KB
testcase_09 AC 162 ms
55,864 KB
testcase_10 WA -
testcase_11 AC 165 ms
55,924 KB
testcase_12 AC 235 ms
62,788 KB
testcase_13 WA -
testcase_14 AC 231 ms
62,264 KB
testcase_15 AC 228 ms
65,084 KB
testcase_16 AC 170 ms
58,248 KB
testcase_17 AC 161 ms
58,220 KB
testcase_18 AC 130 ms
55,856 KB
testcase_19 AC 168 ms
58,264 KB
testcase_20 AC 125 ms
55,916 KB
testcase_21 AC 121 ms
55,700 KB
testcase_22 WA -
testcase_23 AC 232 ms
62,176 KB
testcase_24 AC 170 ms
58,124 KB
testcase_25 AC 169 ms
57,892 KB
testcase_26 AC 121 ms
55,324 KB
testcase_27 AC 134 ms
55,564 KB
testcase_28 WA -
testcase_29 AC 166 ms
56,032 KB
testcase_30 AC 123 ms
55,668 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class No3 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int ans = 1;
        Set oldNo = new HashSet<>();
        Set nowNo = new HashSet<>();
        Set nextNo = new HashSet<>();
        nowNo.add(1);
        oldNo.add(1);
        while (ans != 10000) {
            if (nowNo.contains(n)) {
                System.out.println(ans);
                return;
            }
            for(Iterator<Integer> iterator = nowNo.iterator(); iterator.hasNext(); ) {
                Integer value = iterator.next();
                int i = value;
                int s = 0;
                while (i > 0) {
                    s += i%2;
                    i/=2;
                }
                if (!oldNo.contains(value + s)) {
                    nextNo.add(value + s);
                    oldNo.add(value + s);
                }
                if (!oldNo.contains(value - s)) {
                    nextNo.add(value - s);
                    oldNo.add(value - s);
                }
            }
            nowNo = nextNo;
            nextNo = new HashSet<>();
            ans++;
        }
        System.out.println("-1");

    }
}
0