結果

問題 No.391 CODING WAR
ユーザー atudnatudn
提出日時 2022-12-20 20:57:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,753 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 203,448 KB
実行使用メモリ 5,892 KB
最終ジャッジ日時 2023-08-11 10:27:31
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,576 KB
testcase_01 AC 5 ms
5,584 KB
testcase_02 AC 5 ms
5,576 KB
testcase_03 AC 5 ms
5,696 KB
testcase_04 AC 5 ms
5,568 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 5 ms
5,760 KB
testcase_07 AC 5 ms
5,748 KB
testcase_08 AC 5 ms
5,736 KB
testcase_09 AC 23 ms
5,676 KB
testcase_10 AC 22 ms
5,584 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
5,676 KB
testcase_13 AC 19 ms
5,560 KB
testcase_14 AC 18 ms
5,816 KB
testcase_15 AC 19 ms
5,576 KB
testcase_16 AC 13 ms
5,648 KB
testcase_17 AC 15 ms
5,572 KB
testcase_18 AC 12 ms
5,892 KB
testcase_19 AC 12 ms
5,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define SELECTER(_1,_2,_3,SELECT,...) SELECT
#define rep1(i,n) for(int i=0;i<(int)n;++i)
#define rep2(i,a,n) for(int i=(int)a;i<(int)n;++i)
#define rep(...) SELECTER(__VA_ARGS__,rep2,rep1) (__VA_ARGS__)
#define fi first
#define se second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
using veci=vector<int>;
using vecll=vector<long long>;
using vecpll=vector<pair<long long,long long>>;
using vecs=vector<string>;
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
constexpr ll MOD=1000000007;
constexpr ll INF=1e16;

ll fac[100005],inv[100005],finv[100005];
void init(){
	fac[0]=fac[1]=inv[1]=finv[0]=finv[1]=1;
	for(int i=2;i<100005;++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 comb(int n,int k){
	if(n<0 || k<0 ||n<k)return 0;
	return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

ll modpow(ll a,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*a%MOD;
		a=a*a%MOD;
		n>>=1;
	}
	return res;
}

ll fun(ll n,int k){
	if(n<k) return 0;
	ll res=0;
	for(int i=0;i<=k;++i){
		res=(res+modpow(i,n)*comb(k,i)*((k-i)%2?-1:1)+MOD)%MOD;
	}
	return res;
}

ll bell(int n,int k){
	ll res=0;
	for(int i=0;i<=k;++i){
		res=(res+fun(n,i)*finv[i]%MOD)%MOD;
	}
	return res;
}

ll pertition(int n,int k){
	vector<vecll> dp(n+1,vecll(k+1,0));
	for(int i=0;i<=k;++i) dp[0][i]=1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=k;++j){
			dp[i][j]=(dp[i][j-1]+(i>=j?dp[i-j][j]:0))%MOD;
		}
	}
	return dp[n][k];
}

int main(){
	ll n,m;cin>>n>>m;
	if(n<m){cout<<0<<endl;return 0;}
	init();
	cout<<fun(n,m)<<endl;
}
0