結果

問題 No.1181 Product Sum for All Subsets
ユーザー nikkukunnikkukun
提出日時 2020-08-21 22:20:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 166,128 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 06:03:53
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 5 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 29 ms
6,940 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 27 ms
6,940 KB
testcase_15 AC 22 ms
6,944 KB
testcase_16 AC 29 ms
6,944 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 26 ms
6,940 KB
testcase_19 AC 25 ms
6,940 KB
testcase_20 AC 29 ms
6,940 KB
testcase_21 AC 17 ms
6,940 KB
testcase_22 AC 12 ms
6,944 KB
testcase_23 AC 7 ms
6,944 KB
testcase_24 AC 11 ms
6,944 KB
testcase_25 AC 17 ms
6,944 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 34 ms
6,940 KB
testcase_29 AC 34 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

ll QPow(ll bas, int t) {
	ll ret = 1;
	while (t) {
		if (t & 1) ret = ret * bas % MOD;
		bas = bas * bas % MOD;
		t >>= 1;
	}
	return ret;
}

int fac[N], ifac[N];

void Init() {
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[N - 1] = QPow(fac[N - 1], MOD - 2);
	for (int i = N - 1; i > 0; i--)
		ifac[i - 1] = 1LL * ifac[i] * i % MOD;
}

ll Binom(int n, int a) {
	if (n < 0 || a < 0 || n - a < 0)
		return 0;
	else
		return 1LL * fac[n] * ifac[a] % MOD * ifac[n - a] % MOD;
}

int main() {
	ios::sync_with_stdio(0);

	Init();

	int n;
	ll k;
	cin >> n >> k;
	k %= MOD;

	ll ans = 0;
	ll x = (1 + k) * k / 2 % MOD;
	for (int i = 0; i < n; i++) {
		ll now = Binom(n, i) * QPow(x, i) % MOD * QPow(k, n - i);
		ans = (ans + now) % MOD;
	}
	cout << ans << endl;

	return 0;
}
0