結果

問題 No.3 ビットすごろく
ユーザー tagfatagfa
提出日時 2018-09-01 22:21:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 557 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2023-10-21 16:44:26
合計ジャッジ時間 3,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,464 KB
testcase_01 AC 32 ms
10,464 KB
testcase_02 AC 33 ms
10,464 KB
testcase_03 AC 40 ms
10,496 KB
testcase_04 AC 34 ms
10,468 KB
testcase_05 AC 50 ms
10,568 KB
testcase_06 AC 43 ms
10,500 KB
testcase_07 AC 37 ms
10,476 KB
testcase_08 AC 46 ms
10,540 KB
testcase_09 AC 56 ms
10,604 KB
testcase_10 AC 62 ms
10,640 KB
testcase_11 AC 54 ms
10,592 KB
testcase_12 AC 51 ms
10,564 KB
testcase_13 AC 41 ms
10,484 KB
testcase_14 AC 59 ms
10,632 KB
testcase_15 AC 67 ms
10,680 KB
testcase_16 AC 64 ms
10,660 KB
testcase_17 AC 67 ms
10,676 KB
testcase_18 AC 38 ms
10,480 KB
testcase_19 RE -
testcase_20 AC 34 ms
10,468 KB
testcase_21 AC 32 ms
10,464 KB
testcase_22 AC 60 ms
10,636 KB
testcase_23 AC 67 ms
10,680 KB
testcase_24 AC 66 ms
10,680 KB
testcase_25 AC 67 ms
10,680 KB
testcase_26 AC 32 ms
10,464 KB
testcase_27 AC 39 ms
10,492 KB
testcase_28 AC 64 ms
10,656 KB
testcase_29 AC 54 ms
10,592 KB
testcase_30 AC 33 ms
10,468 KB
testcase_31 AC 33 ms
10,468 KB
testcase_32 AC 52 ms
10,580 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)

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