結果

問題 No.3 ビットすごろく
ユーザー Woo-CieWoo-Cie
提出日時 2019-03-23 02:35:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 622 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 30,000 KB
最終ジャッジ日時 2023-09-14 01:14:14
合計ジャッジ時間 8,678 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,852 KB
testcase_01 AC 133 ms
29,700 KB
testcase_02 AC 133 ms
29,648 KB
testcase_03 AC 140 ms
29,712 KB
testcase_04 AC 134 ms
29,716 KB
testcase_05 AC 155 ms
29,592 KB
testcase_06 AC 142 ms
29,712 KB
testcase_07 AC 138 ms
29,608 KB
testcase_08 AC 154 ms
29,944 KB
testcase_09 AC 167 ms
29,596 KB
testcase_10 AC 180 ms
29,968 KB
testcase_11 AC 166 ms
29,724 KB
testcase_12 AC 159 ms
29,804 KB
testcase_13 AC 149 ms
29,624 KB
testcase_14 AC 178 ms
29,784 KB
testcase_15 AC 182 ms
30,000 KB
testcase_16 AC 184 ms
29,768 KB
testcase_17 AC 188 ms
29,792 KB
testcase_18 AC 143 ms
29,620 KB
testcase_19 AC 190 ms
29,628 KB
testcase_20 AC 136 ms
29,700 KB
testcase_21 AC 134 ms
29,768 KB
testcase_22 AC 176 ms
29,752 KB
testcase_23 AC 188 ms
29,884 KB
testcase_24 AC 197 ms
29,684 KB
testcase_25 AC 189 ms
29,676 KB
testcase_26 AC 129 ms
29,696 KB
testcase_27 AC 143 ms
29,868 KB
testcase_28 AC 185 ms
29,996 KB
testcase_29 AC 169 ms
29,712 KB
testcase_30 AC 135 ms
29,772 KB
testcase_31 AC 136 ms
29,648 KB
testcase_32 AC 166 ms
29,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8-*-
import queue
import numpy as np
if __name__ == '__main__':
    n = int(input())
    q = queue.Queue()
    q.put((1, 1))
    tbl = np.zeros((n))
    tbl[0] = 1

    while not q.empty():
        i, t = q.get()
        if i == n:
            print(t)
            exit()
        tt = i
        d = 0
        while tt > 0:
            d += tt%2
            tt //= 2
        if i - d > 0 and tbl[i-d-1] == 0:
            q.put((i-d, t+1))
            tbl[i-d-1] = 1
        if i + d <= n and tbl[i+d-1] == 0:
            q.put((i+d, t+1))
            tbl[i+d-1] = 1
    print("-1")
0