結果
| 問題 | No.1035 Color Box |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-24 21:40:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 3,040 bytes |
| コンパイル時間 | 2,148 ms |
| コンパイル使用メモリ | 192,960 KB |
| 最終ジャッジ日時 | 2025-01-09 23:21:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1000000007;
template <uint32_t mod>
class modint{
uint64_t value;
public:
constexpr modint(const int64_t x=0) noexcept: value(x % mod + (x < 0 ? mod : 0)){ }
constexpr explicit operator uint64_t() const noexcept{ return value; }
constexpr modint inverse() const noexcept{ return pow(*this, mod-2); }
constexpr bool operator==(const modint &rhs) const noexcept{ return value == rhs.value; }
constexpr bool operator!=(const modint &rhs) const noexcept{ return value != rhs.value; }
constexpr modint operator+() const noexcept{ return modint(*this); }
constexpr modint operator-() const noexcept{ return modint(mod - value); }
constexpr modint operator+(const modint &rhs) const noexcept{ return modint(*this) += rhs; }
constexpr modint operator-(const modint &rhs) const noexcept{ return modint(*this) -= rhs; }
constexpr modint operator*(const modint &rhs) const noexcept{ return modint(*this) *= rhs; }
constexpr modint operator/(const modint &rhs) const noexcept{ return modint(*this) /= rhs; }
constexpr modint &operator+=(const modint &rhs) noexcept{
if((value += rhs.value) >= mod) value -= mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) noexcept{ return *this += mod - rhs.value; }
constexpr modint &operator*=(const modint &rhs) noexcept{
if((value *= rhs.value) >= mod) value %= mod;
return *this;
}
constexpr modint &operator/=(const modint &rhs) noexcept{ return *this *= rhs.inverse(); }
constexpr modint operator++(int) noexcept{
modint ret(*this);
if((++value) >= mod) value -= mod;
return ret;
}
constexpr modint operator--(int) noexcept{
modint ret(*this);
if((value += mod - 1) >= mod) value -= mod;
return ret;
}
constexpr modint &operator++() noexcept{ return *this += 1; }
constexpr modint &operator--() noexcept{ return *this -= 1; }
friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x){ return os << x.value; }
friend std::istream &operator>>(std::istream &is, modint<mod> &x){
int64_t i;
is >> i;
x = modint<mod>(i);
return is;
}
friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y){
modint<mod> ret{1}, m{x};
while(y > 0){
if(y & 1) ret *= m;
m *= m;
y >>= 1;
}
return ret;
}
};
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
static modint<mod> fact[100001], finv[100001];
fact[0] = 1;
for(int i=1;i<=100000;++i) fact[i] = fact[i-1] * i;
finv[100000] = fact[100000].inverse();
for(int i=100000;i>0;--i) finv[i-1] = finv[i] * i;
modint<mod> ans = 0;
for(int i=0;i<=m;++i) ans += modint<mod>{(i&1)?-1:1} * pow(modint<mod>(m-i), n) * fact[m] * finv[m-i] * finv[i];
cout << ans << endl;
return 0;
}