結果

問題 No.1035 Color Box
ユーザー 沙耶花沙耶花
提出日時 2020-04-24 21:35:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 202,844 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-04-23 02:59:18
合計ジャッジ時間 3,245 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
6,816 KB
testcase_01 AC 9 ms
6,912 KB
testcase_02 AC 9 ms
6,912 KB
testcase_03 AC 10 ms
6,784 KB
testcase_04 AC 11 ms
7,040 KB
testcase_05 AC 10 ms
7,040 KB
testcase_06 AC 10 ms
6,912 KB
testcase_07 AC 10 ms
6,912 KB
testcase_08 AC 18 ms
6,784 KB
testcase_09 AC 13 ms
6,912 KB
testcase_10 AC 9 ms
6,912 KB
testcase_11 AC 10 ms
6,784 KB
testcase_12 AC 10 ms
7,040 KB
testcase_13 AC 16 ms
6,912 KB
testcase_14 AC 18 ms
6,784 KB
testcase_15 AC 20 ms
6,912 KB
testcase_16 AC 9 ms
6,912 KB
testcase_17 AC 10 ms
6,912 KB
testcase_18 AC 10 ms
6,912 KB
testcase_19 AC 20 ms
6,784 KB
testcase_20 AC 9 ms
7,040 KB
testcase_21 AC 10 ms
6,944 KB
testcase_22 AC 10 ms
6,940 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 AC 10 ms
6,912 KB
testcase_25 AC 10 ms
6,912 KB
testcase_26 AC 10 ms
6,940 KB
testcase_27 AC 10 ms
6,940 KB
testcase_28 AC 9 ms
6,912 KB
testcase_29 AC 10 ms
6,784 KB
testcase_30 AC 10 ms
6,912 KB
testcase_31 AC 10 ms
6,940 KB
testcase_32 AC 10 ms
6,784 KB
testcase_33 AC 10 ms
6,912 KB
testcase_34 AC 9 ms
6,912 KB
testcase_35 AC 9 ms
6,912 KB
testcase_36 AC 10 ms
6,912 KB
testcase_37 AC 9 ms
7,040 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