結果

問題 No.3 ビットすごろく
ユーザー 67oYG9nh2YMmIci67oYG9nh2YMmIci
提出日時 2020-07-14 17:09:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-28 21:49:31
合計ジャッジ時間 2,807 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,136 KB
testcase_01 AC 39 ms
11,136 KB
testcase_02 AC 34 ms
11,008 KB
testcase_03 AC 39 ms
11,008 KB
testcase_04 AC 35 ms
11,136 KB
testcase_05 AC 50 ms
11,136 KB
testcase_06 AC 42 ms
11,008 KB
testcase_07 AC 40 ms
11,008 KB
testcase_08 AC 46 ms
11,136 KB
testcase_09 AC 53 ms
11,136 KB
testcase_10 AC 58 ms
11,264 KB
testcase_11 AC 52 ms
11,136 KB
testcase_12 AC 49 ms
11,136 KB
testcase_13 AC 39 ms
11,008 KB
testcase_14 RE -
testcase_15 AC 63 ms
11,264 KB
testcase_16 AC 61 ms
11,392 KB
testcase_17 AC 63 ms
11,264 KB
testcase_18 AC 38 ms
11,008 KB
testcase_19 AC 64 ms
11,392 KB
testcase_20 AC 34 ms
11,136 KB
testcase_21 AC 34 ms
11,008 KB
testcase_22 RE -
testcase_23 AC 63 ms
11,392 KB
testcase_24 AC 63 ms
11,264 KB
testcase_25 AC 63 ms
11,264 KB
testcase_26 AC 34 ms
11,008 KB
testcase_27 AC 41 ms
11,136 KB
testcase_28 AC 60 ms
11,264 KB
testcase_29 AC 53 ms
11,136 KB
testcase_30 AC 35 ms
11,008 KB
testcase_31 AC 35 ms
10,880 KB
testcase_32 AC 52 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
N=int(input())
def calcpop(num):
    return bin(num).count("1")

def bit():
    q=queue.Queue()
    q.put(1)
    trout=[-1]*(N+10)
    trout[1]=1

    while q.empty()==False:
        curpos=q.get() #現在のマス目
        popcnt=calcpop(curpos) #現在のマス目を2進数に変換した時の1の数

        if(trout[curpos-popcnt]==-1 and curpos-popcnt>0): #後ろのマスに移動するときの判定・処理
            trout[curpos-popcnt]=trout[curpos]+1 #移動した先に移動数の最小値を記録
            q.put(curpos-popcnt) #このマス目から次は探索を行うためキューに入れる

        if(trout[curpos+popcnt]==-1 and curpos+popcnt<=N): #前のマスに移動する時の判定・処理
            trout[curpos+popcnt] = trout[curpos] + 1 #移動した先に移動数の最小値を記録
            q.put(curpos+popcnt) #このマス目から次は探索を行うためキューに入れる

    print(trout[N])

if __name__ == "__main__":
    bit()
0