結果

問題 No.3 ビットすごろく
ユーザー tagfatagfa
提出日時 2018-09-01 22:06:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 517 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2023-10-21 14:52:37
合計ジャッジ時間 2,919 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,544 KB
testcase_01 AC 33 ms
10,544 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 35 ms
10,544 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 37 ms
10,552 KB
testcase_08 AC 47 ms
10,616 KB
testcase_09 AC 56 ms
10,680 KB
testcase_10 AC 61 ms
10,716 KB
testcase_11 AC 54 ms
10,668 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 65 ms
10,736 KB
testcase_17 AC 67 ms
10,752 KB
testcase_18 AC 38 ms
10,556 KB
testcase_19 RE -
testcase_20 AC 33 ms
10,544 KB
testcase_21 AC 32 ms
10,544 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 66 ms
10,756 KB
testcase_25 AC 65 ms
10,756 KB
testcase_26 AC 32 ms
10,544 KB
testcase_27 AC 40 ms
10,568 KB
testcase_28 AC 62 ms
10,732 KB
testcase_29 AC 54 ms
10,668 KB
testcase_30 AC 32 ms
10,544 KB
testcase_31 AC 32 ms
10,544 KB
testcase_32 AC 51 ms
10,656 KB
権限があれば一括ダウンロードができます

ソースコード

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)
    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