結果

問題 No.262 面白くないビットすごろく
ユーザー vwxyz
提出日時 2025-06-10 10:33:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 79,216 KB
最終ジャッジ日時 2025-06-10 10:33:06
合計ジャッジ時間 1,930 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

@lru_cache(maxsize=None)
def solve(a,b,c):
    if c<=2:
        cnt=0
        while b<2**c:
            b+=b.bit_count()+a
            cnt+=1
        return cnt,b
    cnt0,x0=solve(a,b,c-1)
    cnt1,x1=solve(a+1,x0-2**(c-1),c-1)
    return cnt0+cnt1,x1+2**(c-1)

N=int(input())
ans=1
cur=1
for p in range(40,-1,-1):
    while cur+2**p<=N:
        assert cur+2**(p+1)>N
        q,r=divmod(cur,2**p)
        cnt,d=solve(q.bit_count(),r,p)
        ans+=cnt
        cur=q*2**p+d
if cur!=N:
    ans=-1
print(ans)
0