結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
theory_and_me
|
| 提出日時 | 2019-10-02 23:02:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 2,113 bytes |
| コンパイル時間 | 1,135 ms |
| コンパイル使用メモリ | 159,512 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-03 06:02:58 |
| 合計ジャッジ時間 | 2,021 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
const ll N_MAX = 100005;
ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<N_MAX;i++){
inv[i]=mod-inv[mod%i]*(mod/i)%mod;
fac[i]=fac[i-1]*(ll) i%mod;
finv[i]=finv[i-1]*inv[i]%mod;
}
}
ll combination(ll C, ll D){
if(C<D||C<1) return 0;
return fac[C]*(finv[D]*finv[C-D]%mod)%mod;
}
ll powLL(ll a, ll n){
ll res = 1;
while(n>0){
if(n&1){
res *= a;
res %= mod;
}
a = a*a;
a %= mod;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
make();
ll N, M;
cin >> N >> M;
ll res = 0;
if(N<M){
res = 0;
}else{
for(int k=0;k<=M;k++){
ll tmp = (combination(M, k) * powLL(M-k, N))%mod;
if(k%2){
res -= tmp;
res += mod;
res %= mod;
}else{
res += tmp;
}
}
}
cout << res << endl;
return 0;
}
theory_and_me