結果

問題 No.3 ビットすごろく
ユーザー eiji0313eiji0313
提出日時 2018-01-07 19:02:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 644 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 10,964 KB
最終ジャッジ日時 2023-08-24 23:37:11
合計ジャッジ時間 2,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,492 KB
testcase_01 AC 19 ms
8,520 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 19 ms
8,636 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 22 ms
8,980 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 22 ms
9,044 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 19 ms
8,588 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 18 ms
8,540 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 18 ms
8,524 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


def bfs(start, end):
    visited = []
    queue = deque([start])
    while queue:
        v = queue.popleft()
        visited.append(v)
        if v == end:
            return visited
        for n in g[v]:
            if n not in visited:
                queue.append(n)
                break
    return None


N = int(input())
m = []
g = {}
for i in range(1, N + 1):
    m.append("{:b}".format(i).count("1"))
for i in range(len(m)):
    l = []
    if i + m[i] < len(m):
        l.append(i + m[i])
    if i - m[i] >= 0:
        l.append(i - m[i])
    g[i] = l

path = bfs(0, N - 1)
if path:
    print(len(path))
0