結果

問題 No.1181 Product Sum for All Subsets
ユーザー 👑 tamatotamato
提出日時 2020-08-21 22:24:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 65,664 KB
最終ジャッジ日時 2024-04-23 06:06:17
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
63,232 KB
testcase_01 AC 51 ms
63,616 KB
testcase_02 AC 56 ms
65,024 KB
testcase_03 AC 48 ms
63,488 KB
testcase_04 AC 46 ms
63,360 KB
testcase_05 AC 48 ms
63,104 KB
testcase_06 AC 48 ms
63,360 KB
testcase_07 AC 48 ms
63,488 KB
testcase_08 AC 49 ms
63,360 KB
testcase_09 AC 49 ms
63,616 KB
testcase_10 AC 51 ms
63,872 KB
testcase_11 AC 48 ms
63,232 KB
testcase_12 AC 181 ms
65,280 KB
testcase_13 AC 76 ms
64,768 KB
testcase_14 AC 173 ms
65,408 KB
testcase_15 AC 144 ms
65,280 KB
testcase_16 AC 190 ms
64,896 KB
testcase_17 AC 105 ms
65,024 KB
testcase_18 AC 166 ms
65,152 KB
testcase_19 AC 160 ms
65,280 KB
testcase_20 AC 188 ms
65,024 KB
testcase_21 AC 122 ms
64,896 KB
testcase_22 AC 91 ms
65,024 KB
testcase_23 AC 69 ms
65,664 KB
testcase_24 AC 85 ms
65,664 KB
testcase_25 AC 116 ms
65,024 KB
testcase_26 AC 55 ms
65,408 KB
testcase_27 AC 51 ms
63,232 KB
testcase_28 AC 210 ms
65,024 KB
testcase_29 AC 206 ms
64,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    nmax = 2 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    N, K = map(int, input().split())

    S = (K * (K+1) // 2)%mod
    ans = 0
    for i in range(1, N+1):
        ans = (ans + ((pow(K, i, mod) * comb(N, i))%mod * pow(S, N-i, mod))%mod)%mod
    print(ans)


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