結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
むかで
|
| 提出日時 | 2019-09-03 13:17:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,107 bytes |
| コンパイル時間 | 1,638 ms |
| コンパイル使用メモリ | 164,568 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-12-23 21:30:00 |
| 合計ジャッジ時間 | 29,744 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 9 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
template<::std::uint_fast64_t mod>
class ModInt{
private:
using value_type = ::std::uint_fast64_t;
value_type n;
public:
ModInt() : n(0) {}
ModInt(value_type n_) : n(n_ % mod) {}
ModInt(const ModInt& m) : n(m.n) {}
template<typename T>
explicit operator T() const { return static_cast<T>(n); }
value_type get() const { return n; }
friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) {
return os << a.n;
}
friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) {
value_type x;
is >> x;
a = ModInt<mod>(x);
return is;
}
bool operator==(const ModInt& m) const { return n == m.n; }
bool operator!=(const ModInt& m) const { return n != m.n; }
ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; }
ModInt pow(value_type b) const{
ModInt ans = 1, m = ModInt(*this);
while(b){
if(b & 1) ans *= m;
m *= m;
b >>= 1;
}
return ans;
}
ModInt inv() const { return (*this).pow(mod-2); }
ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; }
ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; }
ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
ModInt& operator++(){ n += 1; return *this; }
ModInt& operator--(){ n -= 1; return *this; }
ModInt operator++(int){
ModInt old(n);
n += 1;
return old;
}
ModInt operator--(int){
ModInt old(n);
n -= 1;
return old;
}
ModInt operator-() const { return ModInt(mod-n); }
static ModInt fact(unsigned int x){
if (x <= 1){
ModInt ret(1);
return ret;
}
return fact(x-1)*x;
}
static ModInt comb(unsigned int x, unsigned int y){
if (x < y){
ModInt ret(0);
return ret;
}
return fact(x)/(fact(y)*fact(x-y));
}
static ModInt homo(unsigned int x, unsigned int y){
return comb(x+y-1, y);
}
};
const ll MOD = 1e9+7;
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m; cin>>n>>m;
if (n < m){
cout << "0\n";
}else{
ModInt<MOD> ans;
rep(i, m){
ModInt<MOD> p(m-i);
if (i%2==0){
ans += ModInt<MOD>::comb(m, i)*p.pow(n);
}else{
ans -= ModInt<MOD>::comb(m, i)*p.pow(n);
}
}
cout << ans << "\n";
}
return 0;
}
むかで