結果

問題 No.391 CODING WAR
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-07-08 23:56:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 165,788 KB
実行使用メモリ 5,124 KB
最終ジャッジ日時 2023-08-03 10:49:57
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,932 KB
testcase_01 AC 4 ms
4,972 KB
testcase_02 AC 4 ms
4,944 KB
testcase_03 AC 4 ms
5,052 KB
testcase_04 AC 4 ms
5,124 KB
testcase_05 AC 4 ms
4,996 KB
testcase_06 AC 3 ms
5,040 KB
testcase_07 AC 4 ms
4,984 KB
testcase_08 AC 3 ms
5,120 KB
testcase_09 AC 21 ms
5,108 KB
testcase_10 AC 21 ms
4,968 KB
testcase_11 AC 11 ms
4,992 KB
testcase_12 AC 4 ms
4,936 KB
testcase_13 AC 19 ms
4,988 KB
testcase_14 AC 17 ms
4,980 KB
testcase_15 AC 18 ms
4,916 KB
testcase_16 AC 12 ms
4,984 KB
testcase_17 AC 15 ms
5,048 KB
testcase_18 AC 10 ms
4,980 KB
testcase_19 AC 11 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

ll powmod (ll a, ll p) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
		if ((p & 1) == 1) ans = (ans * mul) % mod;
	}
	return ans;
}

const int MAX_N = 100010;

ll fact[MAX_N];
ll revFact[MAX_N];
// !!!!!!!!SET FACT!!!!!!!
void setFact(int N) {
	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
	}
	revFact[N - 1] = powmod(fact[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--) {
		revFact[i] = revFact[i + 1] * (i + 1);
		revFact[i] %= mod;
	}
}

ll getC(int a, int b) {
	return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

	int N, M;
	cin >> N >> M;
	setFact(MAX_N);
	int ans = 0;
	for (int x = M; x > 0; x--) {
		ans += ((M - x) % 2 ? -1 : 1) * getC(M, x) * powmod(x, N);
		ans %= mod;
	}

	cout << (ans + mod) % mod << endl;
}
0