結果

問題 No.737 PopCount
ユーザー maspymaspy
提出日時 2020-02-26 23:11:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 714 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 16:37:35
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 30 ms
10,624 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 30 ms
10,624 KB
testcase_05 AC 31 ms
10,624 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 30 ms
10,624 KB
testcase_09 AC 31 ms
10,624 KB
testcase_10 AC 30 ms
10,624 KB
testcase_11 AC 31 ms
10,624 KB
testcase_12 AC 30 ms
10,624 KB
testcase_13 AC 30 ms
10,624 KB
testcase_14 AC 31 ms
10,624 KB
testcase_15 AC 30 ms
10,624 KB
testcase_16 AC 30 ms
10,624 KB
testcase_17 AC 30 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
from functools import lru_cache

# %%
N = int(read())
MOD = 10**9 + 7


# %%
@lru_cache(None)
def f(N):
    """return (sum of x*popcount(x), sum of x, sum of popcount(x), sum of 1) for 0 <= x <= N"""
    if N <= 1:
        return N, N, N, N + 1
    Sxp = 0
    Sx = 0
    Sp = 0
    S1 = 0
    # 2x
    a, b, c, d = f(N // 2)
    Sxp += 2 * a
    Sx += 2 * b
    Sp += c
    S1 += d
    # 2x+1
    a, b, c, d = f((N - 1) // 2)
    Sxp += 2 * a + 2 * b + c + d
    Sx += 2 * b + d
    Sp += c + d
    S1 += d
    return Sxp, Sx, Sp, S1


# %%
print(f(N)[0] % MOD)
0