結果

問題 No.3 ビットすごろく
ユーザー howakurohowakuro
提出日時 2020-05-11 23:49:55
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 578 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-09-26 14:28:41
合計ジャッジ時間 10,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 15 ms
7,788 KB
testcase_03 AC 65 ms
7,748 KB
testcase_04 WA -
testcase_05 AC 247 ms
8,472 KB
testcase_06 AC 78 ms
8,300 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 236 ms
8,456 KB
testcase_13 AC 50 ms
7,744 KB
testcase_14 AC 534 ms
8,552 KB
testcase_15 AC 818 ms
8,592 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 553 ms
8,648 KB
testcase_23 AC 836 ms
8,748 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcnt(n):
    return bin(n).count("1")

def main():
    N = int(input())
    visited = []
    q = [[1,0]]
    while q:
        node = q.pop()
        visited.append(node[0])
        if node[0] == N:
            print(node[1])
            return
        add = popcnt(node[0])
        next_node = [node[0]+add,node[1]+1]
        if next_node[0] <= N and not next_node[0] in visited:
            q.append(next_node)
        next_node = [node[0]-add,node[1]+1]
        if next_node[0] >= 1 and not next_node[0] in visited:
            q.append(next_node)
    print(-1)

main()
0