結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,688 KB
testcase_01 AC 17 ms
7,932 KB
testcase_02 AC 16 ms
7,736 KB
testcase_03 AC 18 ms
7,800 KB
testcase_04 AC 16 ms
7,848 KB
testcase_05 AC 22 ms
8,304 KB
testcase_06 AC 19 ms
7,832 KB
testcase_07 AC 17 ms
7,860 KB
testcase_08 AC 21 ms
8,324 KB
testcase_09 AC 24 ms
8,416 KB
testcase_10 AC 26 ms
8,256 KB
testcase_11 AC 24 ms
8,396 KB
testcase_12 AC 22 ms
8,416 KB
testcase_13 AC 18 ms
7,768 KB
testcase_14 AC 25 ms
8,380 KB
testcase_15 AC 29 ms
8,368 KB
testcase_16 AC 27 ms
8,340 KB
testcase_17 AC 29 ms
8,308 KB
testcase_18 AC 17 ms
7,748 KB
testcase_19 AC 28 ms
8,516 KB
testcase_20 AC 16 ms
7,920 KB
testcase_21 AC 16 ms
7,852 KB
testcase_22 AC 26 ms
8,468 KB
testcase_23 AC 30 ms
8,348 KB
testcase_24 AC 27 ms
8,464 KB
testcase_25 AC 28 ms
8,496 KB
testcase_26 AC 14 ms
7,780 KB
testcase_27 AC 19 ms
7,884 KB
testcase_28 AC 27 ms
8,264 KB
testcase_29 AC 23 ms
8,200 KB
testcase_30 AC 15 ms
7,852 KB
testcase_31 AC 16 ms
7,756 KB
testcase_32 AC 22 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

que = [1]
now = 1
visited = [False for i in range(N+1)]
haba = [-1 for i in range(N+1)]
visited[1] = True
haba[1] = 1
haba_count = 1

while len(que) > 0 and now != N:
    now = que.pop(0)
    haba_count = haba[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
        haba[next_f] = haba_count
    if next_b >= 1 and visited[next_b] is False:
        que.append(next_b)
        visited[next_b] = True
        haba[next_b] = haba_count

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