結果

問題 No.3 ビットすごろく
ユーザー yuuki1036yuuki1036
提出日時 2018-11-01 19:45:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 638 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,936 KB
最終ジャッジ日時 2023-09-14 01:09:03
合計ジャッジ時間 2,711 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,572 KB
testcase_01 AC 18 ms
8,496 KB
testcase_02 AC 18 ms
8,460 KB
testcase_03 AC 26 ms
8,436 KB
testcase_04 AC 20 ms
8,584 KB
testcase_05 AC 37 ms
8,652 KB
testcase_06 AC 27 ms
8,636 KB
testcase_07 AC 23 ms
8,468 KB
testcase_08 AC 33 ms
8,652 KB
testcase_09 AC 42 ms
8,640 KB
testcase_10 AC 48 ms
8,772 KB
testcase_11 AC 40 ms
8,788 KB
testcase_12 AC 35 ms
8,688 KB
testcase_13 AC 26 ms
8,532 KB
testcase_14 AC 48 ms
8,744 KB
testcase_15 AC 56 ms
8,936 KB
testcase_16 AC 53 ms
8,776 KB
testcase_17 AC 55 ms
8,844 KB
testcase_18 AC 24 ms
8,484 KB
testcase_19 AC 55 ms
8,928 KB
testcase_20 AC 20 ms
8,596 KB
testcase_21 AC 18 ms
8,456 KB
testcase_22 AC 48 ms
8,792 KB
testcase_23 AC 56 ms
8,888 KB
testcase_24 AC 55 ms
8,920 KB
testcase_25 AC 55 ms
8,920 KB
testcase_26 AC 18 ms
8,444 KB
testcase_27 AC 25 ms
8,504 KB
testcase_28 AC 49 ms
8,820 KB
testcase_29 AC 41 ms
8,692 KB
testcase_30 AC 18 ms
8,496 KB
testcase_31 AC 19 ms
8,452 KB
testcase_32 AC 39 ms
8,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())

def one_counter(num):
    return sum([ int(i) for i in bin(num)[2:] ])

line = [ one_counter(i) for i in range(1,N+1) ]
reach = [ -1 for i in range(N) ]

q = deque([0])
end = N - 1
reach[0] = 1

while q:
    pos = q.popleft()
    
    if pos == end:
        print(reach[-1])
        exit()
    
    next_move = [ line[pos], -line[pos] ]
    
    for m in next_move:
        next_pos = pos + m
        
        if not 0 <= next_pos <= end:
            continue
        
        if reach[next_pos] == -1:
            q.append(next_pos)
            reach[next_pos] = reach[pos] + 1
print(-1)
0