結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,536 KB
testcase_01 AC 18 ms
8,596 KB
testcase_02 AC 19 ms
8,596 KB
testcase_03 AC 27 ms
9,076 KB
testcase_04 AC 20 ms
8,656 KB
testcase_05 AC 35 ms
9,808 KB
testcase_06 AC 25 ms
9,152 KB
testcase_07 AC 22 ms
9,036 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 34 ms
9,760 KB
testcase_13 AC 23 ms
9,004 KB
testcase_14 AC 45 ms
10,320 KB
testcase_15 AC 54 ms
10,820 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 23 ms
9,072 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 18 ms
8,640 KB
testcase_22 AC 46 ms
10,224 KB
testcase_23 AC 55 ms
10,860 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 18 ms
8,528 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 18 ms
8,576 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))
else:
    print("-1")
0