結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
8,952 KB
testcase_01 AC 23 ms
8,908 KB
testcase_02 AC 23 ms
9,056 KB
testcase_03 AC 34 ms
9,028 KB
testcase_04 AC 26 ms
8,924 KB
testcase_05 AC 48 ms
9,236 KB
testcase_06 AC 35 ms
9,056 KB
testcase_07 AC 30 ms
9,040 KB
testcase_08 AC 42 ms
9,160 KB
testcase_09 AC 54 ms
9,224 KB
testcase_10 AC 60 ms
9,216 KB
testcase_11 AC 52 ms
9,176 KB
testcase_12 AC 46 ms
9,216 KB
testcase_13 AC 32 ms
9,008 KB
testcase_14 AC 60 ms
9,272 KB
testcase_15 AC 68 ms
9,344 KB
testcase_16 AC 66 ms
9,248 KB
testcase_17 AC 69 ms
9,404 KB
testcase_18 AC 32 ms
8,960 KB
testcase_19 AC 70 ms
9,344 KB
testcase_20 AC 26 ms
8,960 KB
testcase_21 AC 23 ms
8,964 KB
testcase_22 AC 60 ms
9,320 KB
testcase_23 AC 69 ms
9,424 KB
testcase_24 AC 69 ms
9,428 KB
testcase_25 AC 68 ms
9,412 KB
testcase_26 AC 23 ms
9,020 KB
testcase_27 AC 33 ms
9,024 KB
testcase_28 AC 64 ms
9,252 KB
testcase_29 AC 52 ms
9,236 KB
testcase_30 AC 23 ms
8,912 KB
testcase_31 AC 24 ms
8,952 KB
testcase_32 AC 50 ms
9,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
import sys
INF = 1000000000

n = int(input())
d = [INF for i in range(n)]
visited=[False for i in range(n)] 
dx = [-1, 1]


def calk_walk(n):
    nn = bin(n)
    count = 0
    for i in range(len(nn)):
        if nn[i] == '1':
            count += 1
    return count


def bfs(p):
    q = queue.Queue()
    q.put(p)
    d[p] = 0

    while not q.empty():
        check = q.get()
        if check == n-1:
            break
        for i in range(2):
            np = check + calk_walk(check+1) * dx[i]
            if 0 <= np and np < n and visited[np] == False:
                q.put(np)
                d[np] = d[check] + 1
                visited[np] = True
    return d[n - 1]

if bfs(0) == INF:
    print(-1)
    sys.exit()
print(bfs(0) + 1)
0