結果

問題 No.3 ビットすごろく
ユーザー n_gojon_gojo
提出日時 2020-04-10 18:10:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 175 ms / 5,000 ms
コード長 1,432 bytes
コンパイル時間 3,684 ms
コンパイル使用メモリ 75,988 KB
実行使用メモリ 58,728 KB
最終ジャッジ日時 2023-09-14 01:41:38
合計ジャッジ時間 10,150 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,764 KB
testcase_01 AC 124 ms
55,772 KB
testcase_02 AC 134 ms
57,968 KB
testcase_03 AC 148 ms
57,912 KB
testcase_04 AC 124 ms
55,772 KB
testcase_05 AC 169 ms
58,552 KB
testcase_06 AC 160 ms
57,780 KB
testcase_07 AC 131 ms
55,684 KB
testcase_08 AC 153 ms
56,328 KB
testcase_09 AC 167 ms
55,944 KB
testcase_10 AC 175 ms
58,012 KB
testcase_11 AC 166 ms
56,212 KB
testcase_12 AC 169 ms
57,732 KB
testcase_13 AC 153 ms
57,988 KB
testcase_14 AC 170 ms
57,544 KB
testcase_15 AC 173 ms
58,680 KB
testcase_16 AC 168 ms
58,652 KB
testcase_17 AC 175 ms
56,332 KB
testcase_18 AC 134 ms
55,452 KB
testcase_19 AC 173 ms
58,208 KB
testcase_20 AC 130 ms
55,772 KB
testcase_21 AC 125 ms
55,860 KB
testcase_22 AC 170 ms
58,728 KB
testcase_23 AC 162 ms
58,444 KB
testcase_24 AC 174 ms
58,072 KB
testcase_25 AC 167 ms
57,780 KB
testcase_26 AC 124 ms
55,732 KB
testcase_27 AC 132 ms
55,480 KB
testcase_28 AC 168 ms
57,588 KB
testcase_29 AC 165 ms
55,908 KB
testcase_30 AC 130 ms
55,796 KB
testcase_31 AC 130 ms
55,940 KB
testcase_32 AC 154 ms
55,776 KB
権限があれば一括ダウンロードができます

ソースコード

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) && n >= (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