結果

問題 No.3 ビットすごろく
ユーザー rusa6111rusa6111
提出日時 2019-06-28 22:00:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 430 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 77,928 KB
最終ジャッジ日時 2023-09-14 21:59:40
合計ジャッジ時間 22,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,108 KB
testcase_01 AC 76 ms
71,360 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 92 ms
76,776 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 132 ms
77,132 KB
testcase_08 AC 369 ms
77,852 KB
testcase_09 AC 774 ms
77,368 KB
testcase_10 AC 1,046 ms
77,628 KB
testcase_11 AC 660 ms
77,420 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,277 ms
77,456 KB
testcase_17 AC 1,426 ms
77,688 KB
testcase_18 AC 142 ms
77,004 KB
testcase_19 AC 1,500 ms
77,220 KB
testcase_20 AC 94 ms
76,720 KB
testcase_21 AC 76 ms
71,344 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,500 ms
77,420 KB
testcase_25 AC 1,464 ms
77,316 KB
testcase_26 AC 76 ms
71,312 KB
testcase_27 AC 171 ms
77,204 KB
testcase_28 AC 1,227 ms
77,252 KB
testcase_29 AC 681 ms
77,204 KB
testcase_30 AC 79 ms
76,012 KB
testcase_31 AC 81 ms
76,088 KB
testcase_32 AC 590 ms
77,628 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
for i in range(n):
    for j in range(n):
        if j-b[j]>=0 and c[j-b[j]]>c[j]+1:
            c[j-b[j]]=c[j]+1
        if j+b[j]<n and c[j+b[j]]>c[j]+1:
            c[j+b[j]]=c[j]+1
if c[n-1]:
    print(c[n-1])
else:
    print(-1)
0