結果

問題 No.391 CODING WAR
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-09 00:03:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 163,372 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-21 08:49:58
合計ジャッジ時間 3,639 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
12,864 KB
testcase_01 AC 26 ms
12,928 KB
testcase_02 AC 25 ms
13,056 KB
testcase_03 AC 25 ms
12,928 KB
testcase_04 AC 24 ms
12,928 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 27 ms
12,928 KB
testcase_07 AC 26 ms
13,056 KB
testcase_08 AC 26 ms
12,928 KB
testcase_09 AC 112 ms
12,928 KB
testcase_10 AC 110 ms
13,056 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 26 ms
13,056 KB
testcase_13 AC 93 ms
12,928 KB
testcase_14 AC 85 ms
13,056 KB
testcase_15 AC 93 ms
12,928 KB
testcase_16 AC 71 ms
12,928 KB
testcase_17 AC 77 ms
12,928 KB
testcase_18 AC 60 ms
13,056 KB
testcase_19 AC 59 ms
12,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
ll N, M;
//-----------------------------------------------------------------
ll mo = 1000000007;
ll fact(ll x) {
	const int NUM_ = 400001;
	static ll fac[NUM_ + 1];
	if (fac[0] == 0) {
		fac[0] = 1;
		for (int i = 1; i <= NUM_; ++i) fac[i] = fac[i - 1] * i%mo;
	}
	return fac[x];
}
ll modpow(ll a, ll n) {
	ll r = 1;
	while (n) r = r*((n % 2) ? a : 1) % mo, a = a*a%mo, n >>= 1;
	return r;
}
ll moddiv(ll a, ll b)
{
	ll ap_2 = modpow(b, mo - 2);
	return (a * ap_2) % mo;
}
ll combi(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mo, factr[i] = factr[i - 1] * inv[i] % mo;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mo*factr[N_ - C_] % mo;
}
//-----------------------------------------------------------------
int main() {
	cin >> N >> M;

	if (N < M) {
		printf("0\n");
		return 0;
	}

	ll ans = 0;
	int m = 1;
	rrep(i, M, 1) {
		ll t = (combi(M, i) * modpow(i, N)) % mo;
		ans += m * t;
		ans = (ans + mo) % mo;
		m *= -1;
	}
	cout << ans << endl;
}
0