結果

問題 No.391 CODING WAR
ユーザー kotamanegikotamanegi
提出日時 2019-05-12 19:44:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,714 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 99,044 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-18 13:25:21
合計ジャッジ時間 4,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,508 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 3 ms
4,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 #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long power(long long a,long long now) {
	long long ans = 1;
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		now /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
long long inv(long long a) {
	return power(a, MOD - 2);
}
long long permutation(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MOD;
	}
	return ans;
}
long long combination(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MOD;
		ans *= inv(i + 1);
		ans %= MOD;
	}
	return ans;
}
int main() {
	long long n, m;
	cin >> n >> m;
	if (n < m) {
		cout << 0 << endl;
		return 0;
	}
	long long ans = 0;
	for (long long i = 0; i < m; ++i) {
		long long tmp = combination(m, i);
		tmp *= power(m - i,n);
		tmp %= MOD;
		if (i % 2 == 0) {
			ans += tmp;
		}
		else {
			ans -= tmp;
		}
		ans += MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0