結果

問題 No.3 ビットすごろく
ユーザー niyarinniyarin
提出日時 2017-03-15 13:21:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 6,604 KB
実行使用メモリ 6,708 KB
最終ジャッジ日時 2023-09-14 00:37:05
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
6,660 KB
testcase_01 AC 19 ms
6,708 KB
testcase_02 AC 19 ms
6,428 KB
testcase_03 AC 21 ms
6,448 KB
testcase_04 AC 19 ms
6,512 KB
testcase_05 AC 22 ms
6,452 KB
testcase_06 AC 21 ms
6,652 KB
testcase_07 AC 20 ms
6,416 KB
testcase_08 AC 21 ms
6,448 KB
testcase_09 AC 23 ms
6,516 KB
testcase_10 AC 24 ms
6,452 KB
testcase_11 AC 23 ms
6,428 KB
testcase_12 AC 22 ms
6,428 KB
testcase_13 AC 20 ms
6,552 KB
testcase_14 AC 24 ms
6,556 KB
testcase_15 AC 26 ms
6,424 KB
testcase_16 AC 25 ms
6,588 KB
testcase_17 AC 26 ms
6,584 KB
testcase_18 AC 20 ms
6,512 KB
testcase_19 AC 26 ms
6,600 KB
testcase_20 AC 19 ms
6,508 KB
testcase_21 AC 19 ms
6,500 KB
testcase_22 AC 25 ms
6,496 KB
testcase_23 AC 25 ms
6,420 KB
testcase_24 AC 26 ms
6,444 KB
testcase_25 AC 25 ms
6,432 KB
testcase_26 AC 18 ms
6,544 KB
testcase_27 AC 20 ms
6,548 KB
testcase_28 AC 24 ms
6,580 KB
testcase_29 AC 24 ms
6,552 KB
testcase_30 AC 19 ms
6,424 KB
testcase_31 AC 19 ms
6,500 KB
testcase_32 AC 23 ms
6,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()


d = []
used = []
for i in range(10001):
    d.append(bin(i).count("1"))
    used.append(0)

que = [(1,1)]
ans = -1
while que:
    pos,cnt = que.pop(0)
    if pos == N:
        ans = cnt
        break
    left = pos-d[pos]
    right = pos + d[pos]

    if left>0 and not used[left]:
        used[left] = 1
        que.append((left,cnt+1))
    if right < N+1 and not used[right]:
        used[right] = 1
        que.append((right,cnt+1))

print ans
0