結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2018-08-26 17:49:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 2,583 bytes |
| コンパイル時間 | 1,568 ms |
| コンパイル使用メモリ | 171,516 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 03:57:44 |
| 合計ジャッジ時間 | 2,730 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr lint MOD = 1000000007;
lint N, M;
template <int mod>
struct ModInt
{
using lint = long long;
int val;
ModInt() : val(0) {}
void _setval(lint v) { v = (v % mod) + mod; val = v >= mod ? v - mod : v; }
ModInt(lint v) { _setval(v); }
ModInt operator+(const ModInt &x) const { return ModInt((lint)val + x.val); }
ModInt operator-(const ModInt &x) const { return ModInt((lint)val - x.val); }
ModInt operator*(const ModInt &x) const { return ModInt((lint)val * x.val); }
ModInt operator/(const ModInt &x) const { return ModInt((lint)val * x.inv().val); }
ModInt operator-() const { return ModInt(-val); }
ModInt &operator+=(const ModInt &x) { return *this = *this + x; }
ModInt &operator-=(const ModInt &x) { return *this = *this - x; }
ModInt &operator*=(const ModInt &x) { return *this = *this * x; }
ModInt &operator/=(const ModInt &x) { return *this = *this / x; }
bool operator==(const ModInt &x) { return val == x.val; }
bool operator!=(const ModInt &x) { return val != x.val; }
friend ostream &operator<<(ostream &os, const ModInt &x) { os << x.val; return os; }
lint power(lint n) const {
ModInt ans(1), tmp(val);
while (n) {
if (n & 1) ans *= tmp;
tmp *= tmp;
n /= 2;
}
return ans.val;
}
ModInt inv() const { return this->power(mod - 2); }
ModInt fac() const {
static vector<ModInt> facs;
int l0 = facs.size();
if (l0 > this->val) return facs[this->val];
facs.resize(this->val + 1);
for (int i = l0; i <= this->val; i++) facs[i] = (i == 0 ? 1 : facs[i - 1] * i);
return facs[this->val];
}
ModInt nCr(const ModInt &r) const {
if (this->val < r.val) return ModInt(0);
return this->fac() / ((*this - r).fac() * r.fac());
}
};
using mint = ModInt<MOD>;
int main()
{
cin >> N >> M;
if (M > N) cout << 0 << endl, exit(0);
mint ans = 0;
REP(m, M + 1) // 特定のm問に着手者がいない
{
mint tmp = mint(M).nCr(m) * mint(M - m).power(N);
if (m & 1) ans -= tmp;
else ans += tmp;
}
cout << ans << endl;
}
hitonanode