結果

問題 No.737 PopCount
ユーザー rlangevinrlangevin
提出日時 2023-10-06 12:45:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 1,000 ms
コード長 1,124 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 77,672 KB
最終ジャッジ日時 2023-10-06 12:45:41
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
77,672 KB
testcase_01 AC 107 ms
77,472 KB
testcase_02 AC 103 ms
77,456 KB
testcase_03 AC 106 ms
77,672 KB
testcase_04 AC 105 ms
77,368 KB
testcase_05 AC 107 ms
77,468 KB
testcase_06 AC 102 ms
77,324 KB
testcase_07 AC 107 ms
77,312 KB
testcase_08 AC 105 ms
77,104 KB
testcase_09 AC 110 ms
77,092 KB
testcase_10 AC 87 ms
76,648 KB
testcase_11 AC 90 ms
76,348 KB
testcase_12 AC 97 ms
76,908 KB
testcase_13 AC 98 ms
77,136 KB
testcase_14 AC 102 ms
77,640 KB
testcase_15 AC 91 ms
76,820 KB
testcase_16 AC 99 ms
77,268 KB
testcase_17 AC 110 ms
77,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
mod = 10 ** 9 + 7
M = 65
ans = 0

def solve(k):
    pre0 = [0] * M
    pre1 = [0] * M
    pre0[0] = 1
    val = 0
    for j in range(M):
        n = (N >> (M - 1 - j)) & 1
        dp0 = [0] * M
        dp1 = [0] * M
        for i in range(M):
            if j == k:
                if n:
                    if i:
                        dp0[i] += pre0[i - 1]
                        dp1[i] += pre1[i - 1]
                else:
                    if i:
                        dp1[i] += pre1[i - 1]
                continue

            if n:
                dp1[i] += pre0[i] + pre1[i]
                if i:
                    dp0[i] += pre0[i - 1]
                    dp1[i] += pre1[i - 1]
            else:
                dp0[i] += pre0[i]
                dp1[i] += pre1[i]
                if i:
                    dp1[i] += pre1[i - 1]
        dp0, pre0 = pre0, dp0
        dp1, pre1 = pre1, dp1

    two = 1 << (M - 1 - k)
    for i in range(M):
        val += two * (pre0[i] + pre1[i]) * i
        val %= mod
    
    return val


for k in range(M):
    ans += solve(k)
    ans %= mod

print(ans)
0