結果

問題 No.3 ビットすごろく
ユーザー miho-4miho-4
提出日時 2023-04-08 07:34:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 280 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 70,556 KB
最終ジャッジ日時 2024-04-14 06:59:12
合計ジャッジ時間 3,275 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,940 KB
testcase_01 AC 44 ms
54,700 KB
testcase_02 AC 47 ms
55,112 KB
testcase_03 AC 58 ms
65,352 KB
testcase_04 AC 52 ms
63,160 KB
testcase_05 AC 57 ms
67,080 KB
testcase_06 AC 57 ms
66,332 KB
testcase_07 AC 54 ms
65,136 KB
testcase_08 AC 56 ms
66,632 KB
testcase_09 AC 57 ms
67,404 KB
testcase_10 AC 59 ms
68,896 KB
testcase_11 AC 58 ms
68,888 KB
testcase_12 AC 60 ms
66,972 KB
testcase_13 AC 55 ms
65,092 KB
testcase_14 AC 57 ms
68,272 KB
testcase_15 AC 62 ms
70,272 KB
testcase_16 AC 60 ms
69,064 KB
testcase_17 AC 60 ms
70,496 KB
testcase_18 AC 55 ms
65,112 KB
testcase_19 AC 59 ms
69,740 KB
testcase_20 AC 45 ms
54,812 KB
testcase_21 AC 43 ms
54,648 KB
testcase_22 AC 59 ms
68,276 KB
testcase_23 AC 59 ms
69,892 KB
testcase_24 AC 61 ms
70,076 KB
testcase_25 AC 59 ms
70,556 KB
testcase_26 AC 44 ms
53,840 KB
testcase_27 AC 56 ms
65,032 KB
testcase_28 AC 58 ms
69,264 KB
testcase_29 AC 59 ms
67,908 KB
testcase_30 AC 44 ms
54,844 KB
testcase_31 AC 44 ms
54,076 KB
testcase_32 AC 59 ms
67,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n=int(input())
L=[10**9]*(n+1)
L[1]=1
q=deque([(1,1)])
while q:
    x,t=q.popleft()
    k=bin(x).count("1")
    for dk in [k,-k]:
      if 0<x+dk<=n and t+1<L[x+dk]:
        L[x+dk]=t+1
        q.append((x+dk,t+1))

print(L[n] if L[n]!=10**9 else -1)
0