結果

問題 No.3 ビットすごろく
ユーザー tagfatagfa
提出日時 2018-09-01 22:22:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,684 KB
実行使用メモリ 9,336 KB
最終ジャッジ日時 2023-09-14 01:05:49
合計ジャッジ時間 2,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,984 KB
testcase_01 AC 24 ms
9,128 KB
testcase_02 AC 23 ms
9,092 KB
testcase_03 AC 29 ms
9,036 KB
testcase_04 AC 24 ms
9,132 KB
testcase_05 AC 37 ms
9,060 KB
testcase_06 AC 28 ms
9,016 KB
testcase_07 AC 25 ms
9,156 KB
testcase_08 AC 33 ms
9,260 KB
testcase_09 AC 40 ms
9,172 KB
testcase_10 AC 46 ms
9,296 KB
testcase_11 AC 41 ms
9,092 KB
testcase_12 AC 36 ms
9,184 KB
testcase_13 AC 28 ms
9,000 KB
testcase_14 AC 45 ms
9,196 KB
testcase_15 AC 49 ms
9,244 KB
testcase_16 AC 47 ms
9,244 KB
testcase_17 AC 51 ms
9,172 KB
testcase_18 AC 26 ms
9,064 KB
testcase_19 AC 52 ms
9,320 KB
testcase_20 AC 23 ms
8,976 KB
testcase_21 AC 21 ms
8,908 KB
testcase_22 AC 46 ms
9,220 KB
testcase_23 AC 52 ms
9,336 KB
testcase_24 AC 53 ms
9,108 KB
testcase_25 AC 54 ms
9,264 KB
testcase_26 AC 23 ms
9,096 KB
testcase_27 AC 30 ms
9,000 KB
testcase_28 AC 49 ms
9,232 KB
testcase_29 AC 41 ms
9,020 KB
testcase_30 AC 23 ms
9,024 KB
testcase_31 AC 22 ms
9,048 KB
testcase_32 AC 41 ms
9,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
#移動するマス数を求める関数
def calcpop(num):
    return bin(num).count("1")

N=int(input())
q=queue.Queue()
q.put(1)

masu =[]
masu=[0]*10010
masu[1]=1

while q.empty()==False:

    curpos=q.get()
    popcnt=calcpop(curpos)
    if (curpos-popcnt>0 and masu[curpos-popcnt]==0):
        masu[curpos-popcnt]=masu[curpos]+1
        q.put(curpos-popcnt)
    if (curpos+popcnt<=N and masu[curpos+popcnt]==0):
        masu[curpos+popcnt]=masu[curpos]+1
        q.put(curpos+popcnt)

if masu[N]==0:
    print(-1)
else:
    print(masu[N])
0