結果

問題 No.3 ビットすごろく
ユーザー howakurohowakuro
提出日時 2020-05-12 00:31:52
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 8,972 KB
最終ジャッジ日時 2023-09-14 01:43:31
合計ジャッジ時間 2,077 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,540 KB
testcase_01 AC 19 ms
8,500 KB
testcase_02 AC 20 ms
8,496 KB
testcase_03 AC 22 ms
8,632 KB
testcase_04 AC 19 ms
8,524 KB
testcase_05 AC 22 ms
8,716 KB
testcase_06 AC 20 ms
8,584 KB
testcase_07 AC 20 ms
8,540 KB
testcase_08 AC 22 ms
8,784 KB
testcase_09 AC 23 ms
8,868 KB
testcase_10 AC 24 ms
8,760 KB
testcase_11 AC 23 ms
8,696 KB
testcase_12 AC 22 ms
8,656 KB
testcase_13 AC 20 ms
8,672 KB
testcase_14 AC 24 ms
8,876 KB
testcase_15 AC 25 ms
8,924 KB
testcase_16 AC 25 ms
8,860 KB
testcase_17 AC 25 ms
8,972 KB
testcase_18 AC 20 ms
8,484 KB
testcase_19 AC 26 ms
8,912 KB
testcase_20 AC 19 ms
8,580 KB
testcase_21 AC 19 ms
8,620 KB
testcase_22 AC 25 ms
8,752 KB
testcase_23 AC 26 ms
8,840 KB
testcase_24 AC 26 ms
8,880 KB
testcase_25 AC 26 ms
8,820 KB
testcase_26 AC 18 ms
8,620 KB
testcase_27 AC 21 ms
8,620 KB
testcase_28 AC 25 ms
8,904 KB
testcase_29 AC 23 ms
8,684 KB
testcase_30 AC 19 ms
8,636 KB
testcase_31 AC 19 ms
8,660 KB
testcase_32 AC 23 ms
8,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def main():
    N = int(input())
    visited = [1]+[0]*(N-1)
    q = deque([1])
    while q:
        node = q.popleft()
        if node == N:
            print(visited[node-1])
            return
        add = bin(node).count("1")
        next_node = node+add
        if next_node <= N and visited[next_node-1] == 0:
            q.append(next_node)
            visited[next_node-1] = visited[node-1] + 1
        next_node = node-add
        if next_node >= 1 and visited[next_node-1] == 0:
            q.append(next_node)
            visited[next_node-1] = visited[node-1] + 1
    print(-1)

main()
0