結果

問題 No.3 ビットすごろく
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-18 16:06:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 410 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 78,312 KB
最終ジャッジ日時 2023-08-15 07:29:32
合計ジャッジ時間 5,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,532 KB
testcase_01 AC 83 ms
71,652 KB
testcase_02 AC 84 ms
71,476 KB
testcase_03 AC 110 ms
77,456 KB
testcase_04 AC 94 ms
76,532 KB
testcase_05 AC 112 ms
77,760 KB
testcase_06 AC 104 ms
77,916 KB
testcase_07 AC 102 ms
77,984 KB
testcase_08 AC 112 ms
77,872 KB
testcase_09 AC 111 ms
77,996 KB
testcase_10 AC 114 ms
78,104 KB
testcase_11 AC 110 ms
78,028 KB
testcase_12 AC 109 ms
78,088 KB
testcase_13 AC 104 ms
77,740 KB
testcase_14 AC 118 ms
77,760 KB
testcase_15 AC 114 ms
78,056 KB
testcase_16 AC 110 ms
78,260 KB
testcase_17 AC 113 ms
77,876 KB
testcase_18 AC 101 ms
77,780 KB
testcase_19 AC 118 ms
77,904 KB
testcase_20 AC 95 ms
76,832 KB
testcase_21 AC 84 ms
71,476 KB
testcase_22 AC 114 ms
78,120 KB
testcase_23 AC 113 ms
78,056 KB
testcase_24 AC 112 ms
78,268 KB
testcase_25 AC 115 ms
78,180 KB
testcase_26 AC 85 ms
71,660 KB
testcase_27 AC 105 ms
77,896 KB
testcase_28 AC 117 ms
78,312 KB
testcase_29 AC 115 ms
77,764 KB
testcase_30 AC 86 ms
71,520 KB
testcase_31 AC 85 ms
71,592 KB
testcase_32 AC 113 ms
78,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n=int(input())
d=[-1]*(n+1)
d[1]=1
q=deque()
q.append(1)
while q:
    now=q.popleft()
    num_2=bin(now)[2:]
    move=sum(list(map(int,num_2)))
    if now-move>=1:
        if d[now-move]==-1:
            d[now-move]=d[now]+1
            q.append(now-move)
    if now+move<=n:
        if d[now+move]==-1:
            d[now+move]=d[now]+1
            q.append(now+move)
print(d[-1])
0