結果

問題 No.3 ビットすごろく
ユーザー mmTa
提出日時 2019-07-14 21:20:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,157 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-11-24 16:16:14
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

def count_1bit(num):
    if num == 1:
        return 1
    elif num == 0:
        return 0
    else:
        count = num % 2
        return count + count_1bit(num // 2)


(NOF_NODE) = int(input().rstrip())

# ノードリスト作成
# ノード=0:1ビット数、1:左初めて?、2:右初めて?
nodes = []
for i in range(1, NOF_NODE+1):
    node = [count_1bit(i), True, True]
    nodes.append(node)
# 先頭ノードは左に行けない
nodes[0][1] = False

# 経路探索
nof_pass = 1
current_node = 0
in_progress = True
while in_progress:
    if current_node == NOF_NODE - 1:
        in_progress = False
    else:
        nof_node = nodes[current_node][0]
        if nodes[current_node][2] and (current_node + nof_node <= NOF_NODE - 1):
            nodes[current_node][2] = False
            nof_pass += 1
            current_node += nof_node
        elif nodes[current_node][1] and (current_node - nof_node > 0):
            nodes[current_node][1] = False
            nof_pass += 1
            current_node -= nof_node
        else:
            # たどり着けない
            nof_pass = -1
            in_progress = False

print(nof_pass)
0