結果

問題 No.3 ビットすごろく
ユーザー tyokopontakutyokopontaku
提出日時 2019-10-13 16:42:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-05-09 11:55:50
合計ジャッジ時間 2,576 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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