結果

問題 No.1181 Product Sum for All Subsets
ユーザー rlangevinrlangevin
提出日時 2023-04-09 12:26:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 80,812 KB
最終ジャッジ日時 2024-04-15 03:39:12
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
62,696 KB
testcase_01 AC 43 ms
63,256 KB
testcase_02 AC 50 ms
66,072 KB
testcase_03 AC 42 ms
62,788 KB
testcase_04 AC 44 ms
62,104 KB
testcase_05 AC 43 ms
61,792 KB
testcase_06 AC 43 ms
62,144 KB
testcase_07 AC 45 ms
63,812 KB
testcase_08 AC 44 ms
62,136 KB
testcase_09 AC 49 ms
64,140 KB
testcase_10 AC 46 ms
63,800 KB
testcase_11 AC 43 ms
62,668 KB
testcase_12 AC 171 ms
78,880 KB
testcase_13 AC 76 ms
79,604 KB
testcase_14 AC 167 ms
78,920 KB
testcase_15 AC 147 ms
80,812 KB
testcase_16 AC 176 ms
78,776 KB
testcase_17 AC 106 ms
80,064 KB
testcase_18 AC 162 ms
78,680 KB
testcase_19 AC 157 ms
80,768 KB
testcase_20 AC 177 ms
78,844 KB
testcase_21 AC 120 ms
80,208 KB
testcase_22 AC 92 ms
79,440 KB
testcase_23 AC 66 ms
76,592 KB
testcase_24 AC 88 ms
79,792 KB
testcase_25 AC 115 ms
80,184 KB
testcase_26 AC 55 ms
68,488 KB
testcase_27 AC 44 ms
63,032 KB
testcase_28 AC 195 ms
78,988 KB
testcase_29 AC 145 ms
78,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
mod = 10 ** 9 + 7

n = 202020

fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


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