結果

問題 No.391 CODING WAR
ユーザー autumn-eelautumn-eel
提出日時 2017-12-15 10:46:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 165,136 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-08-21 06:41:25
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,880 KB
testcase_01 AC 3 ms
5,180 KB
testcase_02 AC 3 ms
4,908 KB
testcase_03 AC 4 ms
4,972 KB
testcase_04 AC 4 ms
5,060 KB
testcase_05 AC 4 ms
4,912 KB
testcase_06 AC 3 ms
5,012 KB
testcase_07 AC 4 ms
5,188 KB
testcase_08 AC 4 ms
4,884 KB
testcase_09 AC 48 ms
4,928 KB
testcase_10 AC 47 ms
4,952 KB
testcase_11 AC 3 ms
5,012 KB
testcase_12 AC 4 ms
5,196 KB
testcase_13 AC 46 ms
4,908 KB
testcase_14 AC 37 ms
4,916 KB
testcase_15 AC 42 ms
4,880 KB
testcase_16 AC 26 ms
5,008 KB
testcase_17 AC 30 ms
5,188 KB
testcase_18 AC 21 ms
4,876 KB
testcase_19 AC 22 ms
4,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll fact[200000];

ll C(ll a,ll b){
	return fact[a]*ppow(fact[b],MOD-2)%MOD*ppow(fact[a-b],MOD-2)%MOD;
}
int main(){
	fact[0]=1;for(ll i=1;i<200000;i++)fact[i]=(fact[i-1]*i)%MOD;
	ll n,m;cin>>n>>m;
	if(m>n){
		puts("0");return 0;
	}
	ll ans=0;
	for(ll i=0;i<m;i++){//使わない数
		ll a=(C(m,i)*ppow(m-i,n))%MOD;
		if(i%2)ans=(ans+MOD-a)%MOD;
		else ans=(ans+a)%MOD;
	}
	cout<<ans<<endl;
}
0