結果

問題 No.391 CODING WAR
ユーザー kotamanegikotamanegi
提出日時 2019-05-12 21:21:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,959 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 107,148 KB
実行使用メモリ 22,200 KB
最終ジャッジ日時 2023-09-19 04:42:08
合計ジャッジ時間 3,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 144 ms
22,200 KB
testcase_10 AC 141 ms
22,096 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 138 ms
22,160 KB
testcase_14 AC 103 ms
17,384 KB
testcase_15 AC 119 ms
19,408 KB
testcase_16 AC 65 ms
12,508 KB
testcase_17 AC 84 ms
14,732 KB
testcase_18 AC 52 ms
10,684 KB
testcase_19 AC 54 ms
10,924 KB
権限があれば一括ダウンロードができます

ソースコード

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)
map<pair<long long, long long>, long long> memo;
long long power(long long a,long long now) {
	if (memo[make_pair(a, now)]) return memo[make_pair(a, now)];
	long long ans = 1;
	pair<int, int> base = make_pair(a, now);
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		now /= 2;
		a *= a;
		a %= MOD;
	}
	return memo[base] = 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;
	long long tmpe = 1;
	for (long long i = 0; i < m; ++i) {
		long long tmp = tmpe;
		tmpe *= (m - i);
		tmpe %= MOD;
		tmpe *= inv(i + 1);
		tmpe %= MOD;
		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