結果

問題 No.391 CODING WAR
ユーザー pekempeypekempey
提出日時 2016-07-08 22:54:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 149,328 KB
実行使用メモリ 18,800 KB
最終ジャッジ日時 2023-08-03 08:50:26
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
18,580 KB
testcase_01 AC 21 ms
18,676 KB
testcase_02 AC 21 ms
18,624 KB
testcase_03 AC 22 ms
18,740 KB
testcase_04 AC 21 ms
18,624 KB
testcase_05 AC 21 ms
18,732 KB
testcase_06 AC 22 ms
18,748 KB
testcase_07 AC 21 ms
18,544 KB
testcase_08 AC 22 ms
18,584 KB
testcase_09 AC 39 ms
18,628 KB
testcase_10 AC 39 ms
18,668 KB
testcase_11 AC 29 ms
18,560 KB
testcase_12 AC 22 ms
18,792 KB
testcase_13 AC 37 ms
18,500 KB
testcase_14 AC 36 ms
18,800 KB
testcase_15 AC 36 ms
18,732 KB
testcase_16 AC 31 ms
18,512 KB
testcase_17 AC 32 ms
18,576 KB
testcase_18 AC 28 ms
18,508 KB
testcase_19 AC 29 ms
18,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long long mod = 1e9 + 7;

vector<long long> F, invF;
long long modpow(long long a, long long b, long long mod) {
	long long ret = 1;
	for (; b > 0; a = a * a % mod, b /= 2) if (b & 1) ret = ret * a % mod;
	return ret;
}
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}
void initF(int n) {
	F.resize(n, 1);
	invF.resize(n, 1);
	for (int i = 1; i < n; i++) F[i] = i * F[i - 1] % mod;
	invF[n - 1] = modinv(F[n - 1], mod);
	for (int i = n - 2; i >= 0; i--) invF[i] = invF[i + 1] * (i + 1) % mod;
}
long long P(int a, int b) {
	if (a < b || a < 0 || b < 0) return 0;
	return F[a] * invF[a - b] % mod;
}
long long C(int a, int b) {
	if (a < b || a < 0 || b < 0) return 0;
	return P(a, b) * invF[b] % mod;
}
long long H(int a, int b) {
	if (a == 0 && b == 0) return 1;
	return C(a + b - 1, b);
}

int main() {
	initF(1010101);

	long long n, m;
	cin >> n >> m;

	long long ans = 0;
	for (int i = 1; i <= m; i++) {
		long long v = C(m, i) * modpow(i, n, mod) % mod;
		if ((m - i) % 2 == 1) v = mod - v;
		ans += v;
	}
	cout << ans % mod << endl;
}
0