結果

問題 No.3 ビットすごろく
ユーザー TwizzTwizz
提出日時 2017-02-24 13:33:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 468 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,864 KB
最終ジャッジ日時 2023-09-14 00:21:20
合計ジャッジ時間 2,179 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,716 KB
testcase_01 AC 15 ms
7,848 KB
testcase_02 AC 16 ms
7,808 KB
testcase_03 AC 18 ms
8,304 KB
testcase_04 AC 17 ms
7,788 KB
testcase_05 AC 22 ms
8,596 KB
testcase_06 AC 19 ms
8,208 KB
testcase_07 AC 18 ms
8,204 KB
testcase_08 AC 21 ms
8,588 KB
testcase_09 AC 23 ms
8,540 KB
testcase_10 AC 25 ms
8,852 KB
testcase_11 AC 23 ms
8,668 KB
testcase_12 AC 22 ms
8,512 KB
testcase_13 AC 18 ms
8,248 KB
testcase_14 AC 28 ms
8,864 KB
testcase_15 AC 29 ms
8,780 KB
testcase_16 AC 27 ms
8,768 KB
testcase_17 AC 28 ms
8,788 KB
testcase_18 AC 18 ms
8,220 KB
testcase_19 AC 28 ms
8,824 KB
testcase_20 AC 17 ms
7,824 KB
testcase_21 AC 16 ms
7,804 KB
testcase_22 AC 26 ms
8,792 KB
testcase_23 AC 28 ms
8,800 KB
testcase_24 AC 28 ms
8,732 KB
testcase_25 AC 27 ms
8,744 KB
testcase_26 AC 16 ms
7,864 KB
testcase_27 AC 19 ms
8,256 KB
testcase_28 AC 27 ms
8,768 KB
testcase_29 AC 24 ms
8,644 KB
testcase_30 AC 16 ms
7,848 KB
testcase_31 AC 16 ms
7,760 KB
testcase_32 AC 23 ms
8,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

list={1:1}
que=[(1,1)]
loc=1

while True:
    cnt=que[0][1]+1
    loc=que[0][0]
    mov=(bin(loc)).count("1")

    if loc+mov<=N:
        if loc+mov not in list:
            list[loc+mov]=cnt
            que.append((loc+mov,cnt))
    if loc-mov>=1:
        if loc-mov not in list:
            list[loc-mov]=cnt
            que.append((loc-mov,cnt))
    que.pop(0)

    if que==[]:
        break

if N not in list:
    print(-1)
else:
    print(list[N])
0