結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
tekihei2317
|
| 提出日時 | 2019-05-03 11:43:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,025 bytes |
| コンパイル時間 | 1,628 ms |
| コンパイル使用メモリ | 169,016 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-31 15:31:31 |
| 合計ジャッジ時間 | 2,869 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const int mod=1e9+7;
const int sz=100005;
int fact[sz],inv[sz],ifact[sz];
void make(){
fact[0]=fact[1]=inv[1]=ifact[0]=ifact[1]=1;
for(int i=2;i<sz;i++){
fact[i]=fact[i-1]*i%mod;
inv[i]=inv[mod%i]*(mod-mod/i)%mod;
ifact[i]=ifact[i-1]*inv[i]%mod;
}
}
int comb(int n,int k){
if(n<k) return 0;
return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}
int mod_pow(int x,int n)
{
if(n==0) return 1;
int res=mod_pow(x*x%mod,n/2);
if(n%2==1) res=res*x%mod;
return res;
}
void add(int &a,int b)
{
a+=b;
if(a>=mod) a-=mod;
}
signed main()
{
int N,M; cin>>N>>M;
make();
int ans=mod_pow(M,N);
for(int i=1;i<=M;i++){
int tmp=comb(M,i)*mod_pow(M-i,N)%mod;
if(i&1) add(ans,mod-tmp);
else add(ans,tmp);
}
cout<<ans<<endl;
}
tekihei2317