結果

問題 No.381 名声値を稼ごう Extra
ユーザー lam6er
提出日時 2025-03-31 17:39:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,032 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 52,676 KB
最終ジャッジ日時 2025-03-31 17:40:19
合計ジャッジ時間 9,978 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 1004535809

def main():
    import sys
    input = sys.stdin.read().strip()
    if input == '0':
        print(0)
        return
    
    # Convert decimal string to binary string
    binary = decimal_to_binary(input)
    n = len(binary)
    
    # Calculate the sum of '1's from each position to the end
    sum_ones = [0] * (n + 1)
    for i in range(n-1, -1, -1):
        sum_ones[i] = sum_ones[i+1] + (1 if binary[i] == '1' else 0)
    
    max_ones = max(sum_ones)
    print(max_ones % MOD)

def decimal_to_binary(s):
    if s == '0':
        return '0'
    s = list(s)
    binary = []
    while any(c != '0' for c in s):
        remainder = 0
        new_s = []
        for c in s:
            num = remainder * 10 + int(c)
            q = num // 2
            remainder = num % 2
            if q != 0 or new_s:
                new_s.append(str(q))
        binary.append(str(remainder))
        s = new_s if new_s else ['0']
    return ''.join(reversed(binary)) if binary else '0'

if __name__ == "__main__":
    main()
0