結果

問題 No.3 ビットすごろく
ユーザー DialBirdDialBird
提出日時 2017-03-12 08:17:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 696 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,600 KB
最終ジャッジ日時 2023-09-14 00:35:48
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,340 KB
testcase_01 AC 16 ms
8,336 KB
testcase_02 AC 17 ms
8,184 KB
testcase_03 AC 19 ms
8,224 KB
testcase_04 AC 17 ms
8,192 KB
testcase_05 AC 19 ms
8,300 KB
testcase_06 AC 17 ms
8,348 KB
testcase_07 AC 17 ms
8,364 KB
testcase_08 AC 19 ms
8,408 KB
testcase_09 AC 20 ms
8,388 KB
testcase_10 AC 21 ms
8,348 KB
testcase_11 AC 20 ms
8,332 KB
testcase_12 AC 20 ms
8,336 KB
testcase_13 AC 18 ms
8,360 KB
testcase_14 AC 21 ms
8,336 KB
testcase_15 AC 21 ms
8,552 KB
testcase_16 AC 21 ms
8,396 KB
testcase_17 AC 22 ms
8,412 KB
testcase_18 AC 18 ms
8,388 KB
testcase_19 AC 21 ms
8,424 KB
testcase_20 AC 17 ms
8,188 KB
testcase_21 AC 17 ms
8,328 KB
testcase_22 AC 21 ms
8,412 KB
testcase_23 AC 21 ms
8,512 KB
testcase_24 AC 23 ms
8,600 KB
testcase_25 AC 22 ms
8,452 KB
testcase_26 AC 17 ms
8,356 KB
testcase_27 AC 18 ms
8,380 KB
testcase_28 AC 21 ms
8,564 KB
testcase_29 AC 19 ms
8,436 KB
testcase_30 AC 17 ms
8,328 KB
testcase_31 AC 17 ms
8,196 KB
testcase_32 AC 19 ms
8,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Yukicoder:
    def __init__(self):
        self.n = int(input())

    def run(self):
        dp = [0 for i in range(10001)]
        dp[1] = 1

        queue = [1]
        while len(queue) != 0:
            new_queue = []
            for q in queue:
                if q == self.n:
                    return dp[q]
                cnt = bin(q).count('1')
                for i in [-1, 1]:
                    next_pos = q + cnt*i
                    if 0 < next_pos and next_pos <= self.n and dp[next_pos] == 0:
                        dp[next_pos] = dp[q] + 1
                        new_queue.append(next_pos)
            queue = new_queue
        return -1

y = Yukicoder()
print(y.run())
0