結果

問題 No.3 ビットすごろく
ユーザー rusa6111rusa6111
提出日時 2019-06-28 22:06:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 470 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 76,772 KB
最終ジャッジ日時 2023-09-14 01:21:05
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,308 KB
testcase_01 AC 69 ms
71,452 KB
testcase_02 AC 71 ms
71,348 KB
testcase_03 AC 87 ms
76,664 KB
testcase_04 AC 82 ms
76,548 KB
testcase_05 AC 86 ms
76,524 KB
testcase_06 AC 86 ms
76,508 KB
testcase_07 AC 83 ms
76,588 KB
testcase_08 AC 85 ms
76,372 KB
testcase_09 AC 88 ms
76,616 KB
testcase_10 AC 88 ms
76,592 KB
testcase_11 AC 87 ms
76,624 KB
testcase_12 AC 90 ms
76,684 KB
testcase_13 AC 86 ms
76,584 KB
testcase_14 AC 88 ms
76,756 KB
testcase_15 AC 89 ms
76,592 KB
testcase_16 AC 92 ms
76,772 KB
testcase_17 AC 89 ms
76,632 KB
testcase_18 AC 85 ms
76,544 KB
testcase_19 AC 89 ms
76,720 KB
testcase_20 AC 80 ms
76,468 KB
testcase_21 AC 70 ms
71,544 KB
testcase_22 AC 88 ms
76,624 KB
testcase_23 AC 90 ms
76,636 KB
testcase_24 AC 90 ms
76,388 KB
testcase_25 AC 88 ms
76,636 KB
testcase_26 AC 73 ms
71,484 KB
testcase_27 AC 88 ms
76,628 KB
testcase_28 AC 93 ms
76,644 KB
testcase_29 AC 88 ms
76,680 KB
testcase_30 AC 71 ms
71,624 KB
testcase_31 AC 71 ms
71,312 KB
testcase_32 AC 92 ms
76,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def bc(n):
    c=0
    while n:
        if n%2:
            n-=1
            c+=1
        n=int(n/2)
    return c

n=int(input())
b=[bc(i+1) for i in range(n)]
c=[9999999 for i in range(n)]
c[0]=1
v=1
while(v):
    v=0
    for j in range(n):
        if j-b[j]>=0 and c[j-b[j]]>c[j]+1:
            v=1
            c[j-b[j]]=c[j]+1
        if j+b[j]<n and c[j+b[j]]>c[j]+1:
            v=1
            c[j+b[j]]=c[j]+1
if c[n-1]<n+1:
    print(c[n-1])
else:
    print(-1)
0