結果

問題 No.3 ビットすごろく
ユーザー ondy_candyondy_candy
提出日時 2016-09-24 05:42:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 535 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 8,956 KB
最終ジャッジ日時 2023-09-14 00:08:02
合計ジャッジ時間 2,351 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,516 KB
testcase_01 AC 20 ms
8,568 KB
testcase_02 AC 21 ms
8,580 KB
testcase_03 AC 23 ms
8,596 KB
testcase_04 AC 21 ms
8,492 KB
testcase_05 AC 27 ms
8,788 KB
testcase_06 AC 23 ms
8,604 KB
testcase_07 AC 21 ms
8,580 KB
testcase_08 AC 25 ms
8,672 KB
testcase_09 AC 29 ms
8,800 KB
testcase_10 AC 32 ms
8,832 KB
testcase_11 AC 29 ms
8,776 KB
testcase_12 AC 27 ms
8,796 KB
testcase_13 AC 22 ms
8,668 KB
testcase_14 AC 31 ms
8,800 KB
testcase_15 AC 33 ms
8,856 KB
testcase_16 AC 32 ms
8,864 KB
testcase_17 AC 34 ms
8,956 KB
testcase_18 AC 22 ms
8,576 KB
testcase_19 AC 35 ms
8,948 KB
testcase_20 AC 20 ms
8,648 KB
testcase_21 AC 19 ms
8,496 KB
testcase_22 AC 31 ms
8,832 KB
testcase_23 AC 33 ms
8,956 KB
testcase_24 AC 33 ms
8,864 KB
testcase_25 AC 33 ms
8,764 KB
testcase_26 AC 19 ms
8,472 KB
testcase_27 AC 22 ms
8,688 KB
testcase_28 AC 32 ms
8,824 KB
testcase_29 AC 28 ms
8,700 KB
testcase_30 AC 21 ms
8,516 KB
testcase_31 AC 19 ms
8,652 KB
testcase_32 AC 29 ms
8,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
from collections import deque

n = int(input())

v = [0 for i in range(n + 1)]

q = deque()
q.append(1)
v[1] = 1
result = -1

while(q):
    
    u = q.popleft()
    
    if u == n:
        result = v[u]
        break
    
    steps = str(format(u, 'b')).count('1')
    
    front = u + steps
    back = u - steps
    
    if (1 <= front <= n) and v[front] == 0:
        q.append(front)
        v[front] = v[u] + 1
    if (1<= back <= n) and v[back] == 0:
        q.append(back)
        v[back] = v[u] + 1

print(result)
0