結果

問題 No.3 ビットすごろく
ユーザー phtmscgphtmscg
提出日時 2019-04-18 19:38:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 364 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2023-10-23 16:21:58
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,164 KB
testcase_01 AC 30 ms
10,164 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 29 ms
10,168 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 30 ms
10,188 KB
testcase_08 AC 36 ms
10,300 KB
testcase_09 AC 38 ms
10,408 KB
testcase_10 AC 39 ms
10,444 KB
testcase_11 AC 36 ms
10,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 41 ms
10,468 KB
testcase_17 AC 42 ms
10,484 KB
testcase_18 AC 31 ms
10,200 KB
testcase_19 AC 42 ms
10,488 KB
testcase_20 AC 29 ms
10,164 KB
testcase_21 AC 29 ms
10,164 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 41 ms
10,488 KB
testcase_25 AC 42 ms
10,484 KB
testcase_26 AC 28 ms
10,164 KB
testcase_27 AC 31 ms
10,220 KB
testcase_28 AC 40 ms
10,464 KB
testcase_29 AC 36 ms
10,388 KB
testcase_30 AC 29 ms
10,164 KB
testcase_31 AC 32 ms
10,164 KB
testcase_32 AC 36 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
t = 10**9+7
Q = [t]*N

def bin1(n):
    return bin(n).count("1")

Q = [0]*(N+1)
q = [1]
Q[1] = 1
while q:
    qx = q.pop(0)
    qd = bin1(qx)
    qc = Q[qx]
    if qx + qd < N+1 and Q[qx+qd] == 0:
        Q[qx+qd] = qc + 1
        q.append(qx+qd)
    if qx - qd > 0 and Q[qx-qd] == 0:
        Q[qx-qd] = qc + 1
        q.append(qx-qd)

print(Q[N])
0