結果

問題 No.3 ビットすごろく
ユーザー _karasu32_karasu32
提出日時 2020-01-09 06:45:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 384 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 8,380 KB
最終ジャッジ日時 2023-09-14 01:34:09
合計ジャッジ時間 2,299 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,040 KB
testcase_01 AC 18 ms
7,916 KB
testcase_02 AC 19 ms
8,112 KB
testcase_03 AC 21 ms
7,984 KB
testcase_04 AC 18 ms
7,916 KB
testcase_05 AC 25 ms
7,868 KB
testcase_06 AC 21 ms
7,980 KB
testcase_07 AC 19 ms
7,968 KB
testcase_08 AC 24 ms
7,952 KB
testcase_09 AC 27 ms
8,208 KB
testcase_10 AC 29 ms
8,380 KB
testcase_11 AC 27 ms
8,324 KB
testcase_12 AC 25 ms
7,984 KB
testcase_13 AC 20 ms
8,080 KB
testcase_14 AC 29 ms
8,212 KB
testcase_15 AC 33 ms
8,344 KB
testcase_16 AC 30 ms
8,372 KB
testcase_17 AC 31 ms
8,248 KB
testcase_18 AC 19 ms
7,968 KB
testcase_19 AC 32 ms
8,236 KB
testcase_20 AC 18 ms
7,988 KB
testcase_21 AC 17 ms
8,084 KB
testcase_22 AC 29 ms
8,012 KB
testcase_23 AC 32 ms
8,276 KB
testcase_24 AC 32 ms
8,348 KB
testcase_25 AC 33 ms
8,340 KB
testcase_26 AC 16 ms
7,968 KB
testcase_27 AC 21 ms
8,112 KB
testcase_28 AC 30 ms
8,216 KB
testcase_29 AC 27 ms
8,212 KB
testcase_30 AC 17 ms
8,048 KB
testcase_31 AC 16 ms
8,112 KB
testcase_32 AC 26 ms
7,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
N = int(input())
D = [True]*(N+1)
Q = [(1,1)]
ans = -1
while Q:
    q = heappop(Q)
    if q[1]==N:
        ans=q[0]
        break
    f,b = q[1]+bin(q[1]).count("1"),q[1]-bin(q[1]).count("1")
    if f<=N and D[f]:
        D[f] = False
        heappush(Q,(q[0]+1,f))
    if b>0 and D[b]:
        D[b] = False
        heappush(Q,(q[0]+1,b))
print(ans)
0