結果

問題 No.3 ビットすごろく
ユーザー mkawa2mkawa2
提出日時 2020-01-02 23:15:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 499 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 140,644 KB
最終ジャッジ日時 2023-08-14 18:49:37
合計ジャッジ時間 11,912 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
75,840 KB
testcase_01 AC 66 ms
71,296 KB
testcase_02 AC 65 ms
71,256 KB
testcase_03 AC 346 ms
79,252 KB
testcase_04 AC 139 ms
77,428 KB
testcase_05 AC 2,578 ms
140,644 KB
testcase_06 AC 389 ms
79,092 KB
testcase_07 AC 270 ms
78,572 KB
testcase_08 AC 819 ms
84,852 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
import sys

def II(): return int(sys.stdin.readline())

def main():
    n=II()
    hp=[]
    heappush(hp,[1,1])
    cnt=[-1]*(n+1)
    while hp:
        c,u=heappop(hp)
        if u==n:
            print(c)
            exit()
        d=bin(u).count("1")
        if u+d==n or u-d==n:
            print(c+1)
            exit()
        cnt[u]=c
        if u+d<=n and cnt[u+d]==-1:heappush(hp,[c+1,u+d])
        if u-d>1 and cnt[u-d]==-1:heappush(hp,[c+1,u-d])
    print(-1)

main()
0