結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-15 01:40:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 1,829 bytes |
| コンパイル時間 | 4,314 ms |
| コンパイル使用メモリ | 253,124 KB |
| 最終ジャッジ日時 | 2025-02-21 14:04:25 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
// clang-format off
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class S>inline bool chmax(T &a,const S &b) {return (a<b? a=b,1:0);}
template<class T,class S>inline bool chmin(T &a,const S &b) {return (a>b? a=b,1:0);}
template<class T,class S>inline T floor(T a,S b) {if(b<0)a=-a,b=-b;return a>=0?a/b:(a+1)/b-1;}
template<class T,class S>inline T ceil(T a,S b) {if(b<0)a=-a,b=-b;return a>0?(a-1)/b+1:a/b;}
constexpr int dx[8]={1,0,-1,0,1,-1,1,-1},dy[8]={0,1,0,-1,1,-1,-1,1};
using ll = long long;
// clang-format on
#ifdef LOCAL
#include <util/debug_print.hpp>
#else
#define debug(...) static_cast<void>(0)
#endif
using mint = modint1000000007;
ostream &operator<<(ostream &os, const mint &a) {
return os << a.val();
}
/*
modint 上のCombination計算を行う構造体
計算量
初期化:O(√n)
計算 : O(1)
*/
struct combination {
vector<mint> fact, ifact;
static const int _MAX = 5100000;
combination(int n = _MAX) : fact(n + 1), ifact(n + 1) {
assert(n <= _MAX);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (n == 0 && k == 0) return 1;
if (k < 0 || k > n) return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
combination cmb;
// 制約をやぶる箱の数
mint ans = 0;
for (int i = 0; i <= m; i++) {
mint x = cmb(m, i) * mint(m - i).pow(n);
ans += (i % 2 == 0 ? 1 : -1) * x;
}
cout << ans << '\n';
return 0;
}