結果
問題 | No.391 CODING WAR |
ユーザー | firiexp |
提出日時 | 2019-12-26 22:25:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 3,078 bytes |
コンパイル時間 | 879 ms |
コンパイル使用メモリ | 98,448 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-27 15:46:50 |
合計ジャッジ時間 | 1,885 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 19 ms
6,940 KB |
testcase_10 | AC | 17 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 16 ms
6,940 KB |
testcase_14 | AC | 15 ms
6,940 KB |
testcase_15 | AC | 15 ms
6,940 KB |
testcase_16 | AC | 10 ms
6,944 KB |
testcase_17 | AC | 12 ms
6,940 KB |
testcase_18 | AC | 9 ms
6,940 KB |
testcase_19 | AC | 8 ms
6,940 KB |
ソースコード
#include <limits> #include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using u32 = unsigned; using u64 = unsigned long long; using ll = long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; template<u32 M = 1000000007> struct modint{ u32 val; modint(): val(0){} template<typename T> modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;} modint pow(ll k) const { modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template<typename T> modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;} modint inv() const {return pow(M-2);} modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;} modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;} modint& operator/=(modint a){return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){return modint(M-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; class Factorial { using mint = modint<MOD>; vector<mint> facts, factinv; public: explicit Factorial(int n) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)) { facts[0] = 1; for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*mint(i); factinv[n] = facts[n].inv(); for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * mint(i+1); } mint fact(int k) const { if(k >= 0) return facts[k]; else return factinv[-k]; } mint operator[](const int &k) const { if(k >= 0) return facts[k]; else return factinv[-k]; } mint C(int p, int q) const { if(q < 0 || p < q) return 0; return facts[p] * factinv[q] * factinv[p-q]; } mint P(int p, int q) const { if(q < 0 || p < q) return 0; return facts[p] * factinv[p-q]; } mint H(int p, int q) const { if(p < 0 || q < 0) return 0; return q == 0 ? 1 : C(p+q-1, q); } }; using mint = modint<MOD>; int main() { ll n, m; cin >> n >> m; if(n < m){ puts("0"); return 0; } mint ans = 0; Factorial f(m); vector<mint> powm(m+1, 1); for (int i = 0; i < m; ++i) { if(i & 1) ans -= f.C(m, i)*(mint(m-i).pow(n)); else ans += f.C(m, i)*(mint(m-i).pow(n)); } cout << ans.val << "\n"; return 0; }