結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,024 KB
testcase_01 AC 12 ms
6,144 KB
testcase_02 AC 12 ms
6,140 KB
testcase_03 AC 14 ms
6,092 KB
testcase_04 AC 12 ms
6,216 KB
testcase_05 AC 17 ms
6,044 KB
testcase_06 AC 14 ms
6,068 KB
testcase_07 AC 13 ms
6,040 KB
testcase_08 AC 16 ms
6,012 KB
testcase_09 AC 18 ms
6,248 KB
testcase_10 AC 20 ms
6,212 KB
testcase_11 AC 18 ms
6,148 KB
testcase_12 AC 17 ms
6,172 KB
testcase_13 AC 14 ms
6,152 KB
testcase_14 AC 20 ms
6,316 KB
testcase_15 AC 23 ms
6,328 KB
testcase_16 AC 21 ms
6,168 KB
testcase_17 AC 22 ms
6,364 KB
testcase_18 AC 13 ms
6,220 KB
testcase_19 AC 22 ms
6,232 KB
testcase_20 AC 12 ms
5,972 KB
testcase_21 AC 11 ms
5,980 KB
testcase_22 AC 21 ms
6,320 KB
testcase_23 AC 22 ms
6,336 KB
testcase_24 AC 22 ms
6,188 KB
testcase_25 AC 22 ms
6,436 KB
testcase_26 AC 12 ms
6,024 KB
testcase_27 AC 14 ms
5,976 KB
testcase_28 AC 21 ms
6,336 KB
testcase_29 AC 18 ms
6,112 KB
testcase_30 AC 12 ms
6,084 KB
testcase_31 AC 11 ms
6,204 KB
testcase_32 AC 18 ms
6,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

while locations:
    loc = locations.pop(0)
    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