結果

問題 No.3 ビットすごろく
ユーザー pro_kunipro_kuni
提出日時 2019-10-13 21:37:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 1,138 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 9,224 KB
最終ジャッジ日時 2023-09-14 01:29:15
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,108 KB
testcase_01 AC 23 ms
9,104 KB
testcase_02 AC 23 ms
8,960 KB
testcase_03 AC 34 ms
9,064 KB
testcase_04 AC 26 ms
8,964 KB
testcase_05 AC 50 ms
9,084 KB
testcase_06 AC 35 ms
8,992 KB
testcase_07 AC 30 ms
9,036 KB
testcase_08 AC 43 ms
9,044 KB
testcase_09 AC 56 ms
9,152 KB
testcase_10 AC 64 ms
9,028 KB
testcase_11 AC 53 ms
9,008 KB
testcase_12 AC 49 ms
9,000 KB
testcase_13 AC 32 ms
9,064 KB
testcase_14 AC 62 ms
9,036 KB
testcase_15 AC 73 ms
9,172 KB
testcase_16 AC 69 ms
9,224 KB
testcase_17 AC 72 ms
9,168 KB
testcase_18 AC 30 ms
8,984 KB
testcase_19 AC 74 ms
9,188 KB
testcase_20 AC 25 ms
9,104 KB
testcase_21 AC 22 ms
9,088 KB
testcase_22 AC 63 ms
9,172 KB
testcase_23 AC 74 ms
9,096 KB
testcase_24 AC 74 ms
9,092 KB
testcase_25 AC 74 ms
9,180 KB
testcase_26 AC 22 ms
9,048 KB
testcase_27 AC 35 ms
9,064 KB
testcase_28 AC 68 ms
9,048 KB
testcase_29 AC 54 ms
9,072 KB
testcase_30 AC 22 ms
9,016 KB
testcase_31 AC 23 ms
9,104 KB
testcase_32 AC 51 ms
9,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, queue

class Walker():
    def __init__(self, num):
        self.num = num

    def getNum(self):
        return self.num

    def getStep(self):
        return self.step

    def setStep(self, step):
        self.step = step

    def getMovility(self):
        cnt = 0
        bin_num = bin(self.num)[2:]
        for i in bin_num:
            if int(i):
                cnt += 1
        return cnt

n = int(input())
q = queue.Queue()
current = 1
movility = 1
step = 1

visited = [False for i in range(n)]

while True:
    if current == n:
        print(step)
        break

    if current - movility > 0 and not visited[current - movility - 1]:
        w = Walker(current - movility)
        w.setStep(step + 1)
        q.put(w)
        visited[current - movility - 1] = True
    if current + movility <= n and not visited[current + movility - 1]:
        w = Walker(current + movility)
        w.setStep(step + 1)
        q.put(w)
        visited[current + movility - 1] = True

    if q.empty():
        print(-1)
        break

    w = q.get()
    current = w.getNum()
    step = w.getStep()
    movility = w.getMovility()
0