結果

問題 No.391 CODING WAR
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-07-09 00:02:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 163,664 KB
実行使用メモリ 10,276 KB
最終ジャッジ日時 2024-04-21 08:49:26
合計ジャッジ時間 5,033 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,576 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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 comb(ll a, ll b) {
	ll up = 1;
	rep(i, 0, b) up = (up * a) % mo, a--;
	ll down = 1;
	rep(i, 1, b + 1) down = (down * i) % mo;
	return moddiv(up, down);
}
//-----------------------------------------------------------------
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 = (comb(M, i) * modpow(i, N)) % mo;
		ans += m * t;
		ans = (ans + mo) % mo;
		m *= -1;
	}
	cout << ans << endl;
}
0