結果

問題 No.3 ビットすごろく
ユーザー tyokopontaku
提出日時 2019-10-13 16:42:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-12-16 00:46:45
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 13 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue

num = int(input())
serch_box = queue.Queue()
serch_box.put(1)
count = 2 #boxに2から登録するため
box = [0] * 10000
box[0] = 1

def ten_two(num): #2進数に変換して、1の個数を数える
    a = str(bin(num))
    b = int(a.count("1"))
    return b
    
def box_in(g_masu,r_masu,count): #boxの更新
    if (box[g_masu-1] == 0) and (g_masu <= num):
        box[g_masu-1] = count
        serch_box.put(g_masu)
    elif (box[r_masu-1] == 0) and (r_masu >= 1):
        box[g_masu-1] = count
        serch_box.put(r_masu)
        

while serch_box.qsize() > 0:
    s_num = int(serch_box.get()) #キューから取り出す
    #print("s_num:",str(s_num))
    masu = ten_two(s_num) #対象の数字が進めるor戻れるマスの数
    #print("masu:",str(masu))
    g_masu = int(s_num + masu) #進み先のマス
    r_masu = int(s_num - masu) #戻り先のマス
    #print("g_masu",str(g_masu))
    #print("r_masu",str(r_masu))
    box_in(g_masu,r_masu,count) #boxの更新とキューの更新
    if box[num-1] != 0:
        print(box[num-1])
        break
    if serch_box.qsize() == 0:
        print("-1")
        break
    #print("count:",str(count))
    #print("box:",str(box))
    #print("")
    count += 1 #カウントを1タス
0