結果

問題 No.391 CODING WAR
ユーザー nxterunxteru
提出日時 2018-10-29 23:01:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 166,508 KB
実行使用メモリ 4,992 KB
最終ジャッジ日時 2023-08-12 09:35:30
合計ジャッジ時間 2,724 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 37 ms
4,960 KB
testcase_10 AC 36 ms
4,992 KB
testcase_11 AC 27 ms
4,924 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 33 ms
4,904 KB
testcase_14 AC 27 ms
4,524 KB
testcase_15 AC 31 ms
4,720 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 23 ms
4,424 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 16 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M 1000000007
ll n,m,ans,k[100005],r[100005];
ll pw(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*a%M;
		b>>=1;
		a=a*a%M;
	}
	return res;
}
ll cm(ll a,ll b){
	return k[a]*r[b]%M*r[a-b]%M;
}
int main(void){
    cin>>n>>m;
    k[0]=1,r[0]=1;
    for(ll i=1;i<=m;i++){
		k[i]=k[i-1]*i%M;
		r[i]=pw(k[i],M-2);
	}
	ans=pw(m,n);
	for(ll i=1;i<=m;i++){
		if(i%2)ans=(ans+M-cm(m,i)*pw(m-i,n)%M)%M;
		else ans=(ans+cm(m,i)*pw(m-i,n)%M)%M;
	}
	cout<<ans<<endl;
}
0