結果

問題 No.3 ビットすごろく
ユーザー Kgm1500Kgm1500
提出日時 2018-06-12 20:14:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 734 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 8,844 KB
最終ジャッジ日時 2023-09-14 01:02:37
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,544 KB
testcase_01 AC 18 ms
8,544 KB
testcase_02 AC 18 ms
8,524 KB
testcase_03 AC 20 ms
8,624 KB
testcase_04 AC 20 ms
8,448 KB
testcase_05 AC 25 ms
8,576 KB
testcase_06 AC 21 ms
8,472 KB
testcase_07 AC 20 ms
8,480 KB
testcase_08 AC 22 ms
8,680 KB
testcase_09 AC 26 ms
8,740 KB
testcase_10 AC 28 ms
8,820 KB
testcase_11 AC 26 ms
8,648 KB
testcase_12 AC 23 ms
8,616 KB
testcase_13 AC 19 ms
8,560 KB
testcase_14 AC 27 ms
8,700 KB
testcase_15 AC 31 ms
8,844 KB
testcase_16 AC 29 ms
8,700 KB
testcase_17 AC 29 ms
8,704 KB
testcase_18 AC 20 ms
8,448 KB
testcase_19 AC 30 ms
8,712 KB
testcase_20 AC 19 ms
8,492 KB
testcase_21 AC 18 ms
8,556 KB
testcase_22 AC 29 ms
8,748 KB
testcase_23 AC 30 ms
8,784 KB
testcase_24 AC 30 ms
8,704 KB
testcase_25 AC 30 ms
8,804 KB
testcase_26 AC 18 ms
8,444 KB
testcase_27 AC 20 ms
8,608 KB
testcase_28 AC 29 ms
8,788 KB
testcase_29 AC 25 ms
8,704 KB
testcase_30 AC 18 ms
8,536 KB
testcase_31 AC 17 ms
8,384 KB
testcase_32 AC 24 ms
8,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# N = 11
from collections import deque

N = int(input())

que = deque([])
now = 1
que.append(now)
visited = [False for i in range(N+1)]
step = [-1 for i in range(N+1)]
visited[1] = True
step[1] = 1
step_count = 1

while len(que) > 0 and now != N:
    now = que.popleft()
    step_count = step[now] + 1
    step_width = bin(now).count("1")
    next_f = now + step_width
    next_b = now - step_width
    if next_f <= N and visited[next_f] is False:
        que.append(next_f)
        visited[next_f] = True
        step[next_f] = step_count
    if next_b >= 1 and visited[next_b] is False:
        que.append(next_b)
        visited[next_b] = True
        step[next_b] = step_count

if now == N:
    print(step[N])
else:
    print(-1)
0