結果

問題 No.3 ビットすごろく
ユーザー tagfa
提出日時 2018-09-01 22:05:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-09-21 16:05:35
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 32 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

masu =[]
masu=[0]*10000
masu[1]=1

#キューが無くなるまで繰り返す
while q.empty()==False:

    curpos=q.get()
    popcnt=calcpop(curpos)
    print("curpos=",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)

print(masu[N])
0