結果

問題 No.1035 Color Box
ユーザー 沙耶花沙耶花
提出日時 2020-04-24 21:35:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 204,688 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2023-08-05 04:37:06
合計ジャッジ時間 3,924 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
6,636 KB
testcase_01 AC 10 ms
6,584 KB
testcase_02 AC 10 ms
6,612 KB
testcase_03 AC 11 ms
6,688 KB
testcase_04 AC 11 ms
6,700 KB
testcase_05 AC 11 ms
6,588 KB
testcase_06 AC 12 ms
6,704 KB
testcase_07 AC 11 ms
6,604 KB
testcase_08 AC 18 ms
6,588 KB
testcase_09 AC 14 ms
6,592 KB
testcase_10 AC 11 ms
6,596 KB
testcase_11 AC 11 ms
6,696 KB
testcase_12 AC 10 ms
6,592 KB
testcase_13 AC 16 ms
6,596 KB
testcase_14 AC 17 ms
6,692 KB
testcase_15 AC 18 ms
6,640 KB
testcase_16 AC 10 ms
6,600 KB
testcase_17 AC 11 ms
6,588 KB
testcase_18 AC 11 ms
6,716 KB
testcase_19 AC 19 ms
6,804 KB
testcase_20 AC 11 ms
6,600 KB
testcase_21 AC 11 ms
6,780 KB
testcase_22 AC 11 ms
6,636 KB
testcase_23 AC 11 ms
6,632 KB
testcase_24 AC 11 ms
6,636 KB
testcase_25 AC 10 ms
6,684 KB
testcase_26 AC 11 ms
6,592 KB
testcase_27 AC 11 ms
6,652 KB
testcase_28 AC 11 ms
6,696 KB
testcase_29 AC 11 ms
6,636 KB
testcase_30 AC 10 ms
6,772 KB
testcase_31 AC 11 ms
6,636 KB
testcase_32 AC 11 ms
6,780 KB
testcase_33 AC 10 ms
6,708 KB
testcase_34 AC 11 ms
6,636 KB
testcase_35 AC 11 ms
6,656 KB
testcase_36 AC 11 ms
6,652 KB
testcase_37 AC 11 ms
6,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
	int catalan(int n){
		return mod(combination(2*n,n)*gyakugen(n+1));
	}
	
};

int main(){
	
	int N,M;
	cin>>N>>M;
	
	int ans = 0;
	combi C(400000);
	for(int i=M;i>=1;i--){
		int c = C.combination(M,i);
		c = mod(c * beki(i,N));
		if((M-i)%2==0)ans = mod(ans + c);
		else ans = mod(ans - c);
	}
	cout<<ans<<endl;
	
		
	return 0;
}
0