結果

問題 No.3 ビットすごろく
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-09 13:13:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 586 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 13,164 KB
最終ジャッジ日時 2023-09-14 11:08:59
合計ジャッジ時間 16,762 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,472 KB
testcase_01 AC 20 ms
8,448 KB
testcase_02 AC 19 ms
8,504 KB
testcase_03 AC 988 ms
8,612 KB
testcase_04 AC 84 ms
8,520 KB
testcase_05 AC 4,795 ms
8,688 KB
testcase_06 AC 1,201 ms
8,704 KB
testcase_07 AC 341 ms
8,672 KB
testcase_08 AC 2,496 ms
8,644 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
dp = [10**9 for _ in range(N+1)]

from collections import deque
stack = deque([1])

dp[1] = 1
# stack = [1]
while stack:
    i = stack.pop()
    cnt = bin(i).count("1")

    if i == N:
        continue

    if 1 <= i+cnt  <= N:
        if dp[i]+1 < dp[i+cnt] :
            stack.append( i+cnt )
            dp[i+cnt] = dp[i]+1

    if 1 <=  i-cnt  <= N:
        if dp[i]+1 < dp[i-cnt] :
            stack.append( i-cnt )
            dp[i-cnt] = dp[i]+1

print(dp[N] if dp[N] != 10**9 else -1)

0