結果

問題 No.3 ビットすごろく
ユーザー siro53siro53
提出日時 2019-01-09 18:00:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-05-03 03:53:13
合計ジャッジ時間 2,382 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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
    visited[p] = True

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