結果

問題 No.3 ビットすごろく
ユーザー steek79steek79
提出日時 2015-10-23 14:04:22
言語 Python2
(2.7.18)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 546 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 6,596 KB
実行使用メモリ 6,808 KB
最終ジャッジ日時 2023-09-13 23:26:30
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,412 KB
testcase_01 AC 14 ms
6,384 KB
testcase_02 AC 13 ms
6,400 KB
testcase_03 AC 16 ms
6,416 KB
testcase_04 AC 14 ms
6,404 KB
testcase_05 AC 18 ms
6,612 KB
testcase_06 AC 16 ms
6,408 KB
testcase_07 AC 15 ms
6,464 KB
testcase_08 AC 17 ms
6,488 KB
testcase_09 AC 21 ms
6,512 KB
testcase_10 AC 22 ms
6,632 KB
testcase_11 AC 19 ms
6,444 KB
testcase_12 AC 18 ms
6,424 KB
testcase_13 AC 15 ms
6,392 KB
testcase_14 AC 21 ms
6,724 KB
testcase_15 AC 23 ms
6,552 KB
testcase_16 AC 22 ms
6,808 KB
testcase_17 AC 23 ms
6,668 KB
testcase_18 AC 15 ms
6,528 KB
testcase_19 AC 23 ms
6,544 KB
testcase_20 AC 13 ms
6,320 KB
testcase_21 AC 13 ms
6,556 KB
testcase_22 AC 21 ms
6,540 KB
testcase_23 AC 23 ms
6,592 KB
testcase_24 AC 23 ms
6,600 KB
testcase_25 AC 23 ms
6,780 KB
testcase_26 AC 13 ms
6,484 KB
testcase_27 AC 15 ms
6,392 KB
testcase_28 AC 22 ms
6,764 KB
testcase_29 AC 20 ms
6,548 KB
testcase_30 AC 13 ms
6,508 KB
testcase_31 AC 14 ms
6,556 KB
testcase_32 AC 19 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = input()
been = [-1] + [1] + [-1] * N
locations = deque()
locations.append(1)

while locations:
    loc = locations.popleft()
    width = bin(loc).count('1')
    move_r, move_l = loc + width, loc-width
    if move_r <= N:
        if been[move_r] == -1:
            been[move_r] = been[loc] + 1
            locations.append(move_r)
    if move_l >= 1 and been[move_l] == -1:
        been[move_l] = been[loc] + 1
        locations.append(move_l)
    if been[N] != -1:
        print been[N]
        exit()

print -1
0