結果

問題 No.391 CODING WAR
ユーザー 夜
提出日時 2021-03-02 19:49:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 95,128 KB
実行使用メモリ 8,264 KB
最終ジャッジ日時 2024-04-14 04:50:55
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,132 KB
testcase_01 AC 17 ms
8,260 KB
testcase_02 AC 16 ms
8,264 KB
testcase_03 AC 15 ms
8,260 KB
testcase_04 AC 15 ms
8,260 KB
testcase_05 AC 16 ms
8,132 KB
testcase_06 AC 16 ms
8,132 KB
testcase_07 AC 16 ms
8,256 KB
testcase_08 AC 16 ms
8,260 KB
testcase_09 AC 94 ms
8,260 KB
testcase_10 AC 89 ms
8,260 KB
testcase_11 AC 55 ms
8,136 KB
testcase_12 AC 16 ms
8,140 KB
testcase_13 AC 83 ms
8,132 KB
testcase_14 AC 73 ms
8,260 KB
testcase_15 AC 81 ms
8,132 KB
testcase_16 AC 55 ms
8,256 KB
testcase_17 AC 63 ms
8,260 KB
testcase_18 AC 47 ms
8,260 KB
testcase_19 AC 48 ms
8,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 1000000007;
long long modpow(long long x, long long y) {
	x %= mod;
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
long long fac[200020], finv[200020], inv[200020];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
	COMinit();
	long long n, m;
	cin >> n >> m;
	long long ans = modpow(m, n);
	for (long long i = m - 1; i > 0; i--) {
		if ((i - m + 1) % 2 == 0) {
			ans -= COM(m, i) * modpow(i, n) % mod;
			ans %= mod;
		}
		else {
			ans += COM(m, i) * modpow(i, n) % mod;
			ans %= mod;
		}
	}
	cout << (ans + mod) % mod << endl;
}
0