結果

問題 No.3 ビットすごろく
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-04-05 10:21:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 409 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2023-08-28 22:27:41
合計ジャッジ時間 5,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 93 ms
71,300 KB
testcase_03 AC 106 ms
77,236 KB
testcase_04 WA -
testcase_05 AC 112 ms
77,256 KB
testcase_06 AC 107 ms
77,488 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 112 ms
77,364 KB
testcase_13 AC 106 ms
77,148 KB
testcase_14 AC 114 ms
77,408 KB
testcase_15 AC 115 ms
77,624 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 110 ms
77,292 KB
testcase_23 AC 116 ms
77,388 KB
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 #

from collections import deque
n = int(input())
inf = 10**10
dp = [inf]*(n+2)
dp[1] = 0

q = deque([1])
while q:
    now = q.popleft()
    b = bin(now).count("1")
    if now+b <= n and dp[now+b] > dp[now]+1:
        dp[now+b] = dp[now]+1
        q.append(now+b)
    if now-b > 0 and dp[now-b] > dp[now]+1:
        dp[now-b] = dp[now]+1
        q.append(now-b)
ans = dp[n]
if ans == inf:
    ans = -1
print(ans)
0