結果

問題 No.1181 Product Sum for All Subsets
ユーザー pes_magicpes_magic
提出日時 2020-08-21 22:46:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 73,264 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-23 06:16:26
合計ジャッジ時間 2,023 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,936 KB
testcase_01 AC 7 ms
8,064 KB
testcase_02 AC 8 ms
7,936 KB
testcase_03 AC 6 ms
8,064 KB
testcase_04 AC 6 ms
7,936 KB
testcase_05 AC 6 ms
8,064 KB
testcase_06 AC 7 ms
7,936 KB
testcase_07 AC 7 ms
8,064 KB
testcase_08 AC 7 ms
7,936 KB
testcase_09 AC 7 ms
7,936 KB
testcase_10 AC 8 ms
8,064 KB
testcase_11 AC 6 ms
7,936 KB
testcase_12 AC 52 ms
8,064 KB
testcase_13 AC 16 ms
8,064 KB
testcase_14 AC 47 ms
8,064 KB
testcase_15 AC 39 ms
8,064 KB
testcase_16 AC 53 ms
7,936 KB
testcase_17 AC 25 ms
7,936 KB
testcase_18 AC 47 ms
8,064 KB
testcase_19 AC 42 ms
7,936 KB
testcase_20 AC 51 ms
7,936 KB
testcase_21 AC 29 ms
7,936 KB
testcase_22 AC 20 ms
8,064 KB
testcase_23 AC 12 ms
7,936 KB
testcase_24 AC 18 ms
7,936 KB
testcase_25 AC 30 ms
7,936 KB
testcase_26 AC 8 ms
7,936 KB
testcase_27 AC 7 ms
7,936 KB
testcase_28 AC 60 ms
8,064 KB
testcase_29 AC 60 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

int main(){
    const int maxSize = 200001;
    vector<long long> inv(maxSize);
	vector<long long> fact(maxSize);
	vector<long long> factInv(maxSize);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<maxSize;i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    long long N, K;
    while(cin >> N >> K){
        long long res = 0;
        long long s = K%MOD * ((K+1)%MOD) % MOD * inv[2] % MOD;
        for(int i=0;i<N;i++){
            long long sp = modPow(s, i);
            sp = (sp * comb(N, i)) % MOD;
            sp = (sp * modPow(K%MOD, N-i)) % MOD;
            res = (res + sp) % MOD;
        }
        cout << res << endl;
    }
}
0