結果

問題 No.1181 Product Sum for All Subsets
ユーザー nikkukun
提出日時 2020-08-21 22:20:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 167,436 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 05:50:29
合計ジャッジ時間 3,077 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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