結果

問題 No.391 CODING WAR
ユーザー finefine
提出日時 2017-03-14 22:38:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 164,396 KB
実行使用メモリ 5,056 KB
最終ジャッジ日時 2023-09-12 12:23:41
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 26 ms
5,056 KB
testcase_10 AC 25 ms
4,916 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 22 ms
4,992 KB
testcase_14 AC 19 ms
4,788 KB
testcase_15 AC 21 ms
4,708 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 16 ms
4,388 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll f[100010], f_inv[100010];

ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	if (n < m) {
		cout << 0 << endl;
		return 0;
	}
	f[0] = 1;
	for (int i = 1; i <= m; i++) {
		f[i] = f[i - 1] * i % MOD;
	}
	f_inv[m] = modpow(f[m], MOD - 2);
	for (int i = m; i > 0; i--) {
		f_inv[i - 1] = f_inv[i] * i % MOD;
	}
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		ll tmp = f[m] * f_inv[i] % MOD * f_inv[m - i] % MOD;
		(tmp *= modpow(m - i, n)) %= MOD;
		if (i % 2 == 0) {
			(ans += tmp) %= MOD;
		} else {
			(ans += MOD - tmp) %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}
0