結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 148 ms
56,240 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
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 = 4179;//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