結果
| 問題 | No.1035 Color Box |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-24 22:51:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 2,000 ms |
| コード長 | 1,343 bytes |
| コンパイル時間 | 1,416 ms |
| コンパイル使用メモリ | 170,836 KB |
| 実行使用メモリ | 8,688 KB |
| 最終ジャッジ日時 | 2024-10-15 03:19:33 |
| 合計ジャッジ時間 | 2,580 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
const int nmax=200005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<nmax;i++){
fac[i]=fac[i-1]*i%mod;
inv[i]=mod-inv[mod%i]*(mod/i)%mod;
finv[i]=finv[i-1]*inv[i]%mod;
}
}
ll com(int n,int k){
if(n<k||n<0||k<0){
return 0;
}
return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll pow_mod(ll n,ll k,ll m){
ll res=1;
for(;k>0;k>>=1){
if(k&1){
res=(res*n)%m;
}
n=(n*n)%m;
}
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,m;cin >> n >> m;
if(m>n){
cout << 0 << endl;
}
vector<ll> t(n+1);
t[0]=1;
for(int i=1;i<=n;i++){
(t[i]=t[i-1]*n)%=mod;
}
COMinit();
ll ans=0;
for(ll i=m;i>=1;i--){
ll tmp=pow_mod(i,n,mod)*com(m,i)%mod;
if((m-i)%2==0){
(ans+=tmp)%=mod;
}
else{
(ans+=-tmp+mod)%=mod;
}
}
cout << ans << endl;
}