結果

問題 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
コンパイル時間 264 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 9,236 KB
最終ジャッジ日時 2023-08-22 05:59:52
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,144 KB
testcase_01 AC 22 ms
8,988 KB
testcase_02 AC 23 ms
9,164 KB
testcase_03 AC 25 ms
9,116 KB
testcase_04 AC 23 ms
9,100 KB
testcase_05 AC 28 ms
9,128 KB
testcase_06 AC 26 ms
9,020 KB
testcase_07 AC 25 ms
8,992 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 28 ms
9,068 KB
testcase_13 AC 25 ms
9,088 KB
testcase_14 AC 29 ms
9,132 KB
testcase_15 AC 31 ms
9,196 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 25 ms
9,088 KB
testcase_19 RE -
testcase_20 WA -
testcase_21 AC 23 ms
9,008 KB
testcase_22 AC 29 ms
9,080 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 AC 23 ms
9,028 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 23 ms
8,988 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