結果

問題 No.1181 Product Sum for All Subsets
ユーザー 沙耶花沙耶花
提出日時 2020-08-21 21:59:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 205,508 KB
実行使用メモリ 11,736 KB
最終ジャッジ日時 2023-08-05 08:04:08
合計ジャッジ時間 4,597 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
11,512 KB
testcase_01 AC 25 ms
11,736 KB
testcase_02 AC 25 ms
11,412 KB
testcase_03 AC 26 ms
11,468 KB
testcase_04 AC 25 ms
11,436 KB
testcase_05 AC 25 ms
11,580 KB
testcase_06 AC 25 ms
11,404 KB
testcase_07 AC 25 ms
11,444 KB
testcase_08 AC 25 ms
11,384 KB
testcase_09 AC 25 ms
11,536 KB
testcase_10 AC 26 ms
11,464 KB
testcase_11 AC 25 ms
11,496 KB
testcase_12 AC 56 ms
11,432 KB
testcase_13 AC 31 ms
11,384 KB
testcase_14 AC 55 ms
11,516 KB
testcase_15 AC 47 ms
11,440 KB
testcase_16 AC 57 ms
11,544 KB
testcase_17 AC 37 ms
11,524 KB
testcase_18 AC 53 ms
11,496 KB
testcase_19 AC 50 ms
11,480 KB
testcase_20 AC 57 ms
11,504 KB
testcase_21 AC 42 ms
11,460 KB
testcase_22 AC 34 ms
11,444 KB
testcase_23 AC 29 ms
11,560 KB
testcase_24 AC 34 ms
11,380 KB
testcase_25 AC 41 ms
11,612 KB
testcase_26 AC 26 ms
11,516 KB
testcase_27 AC 24 ms
11,404 KB
testcase_28 AC 63 ms
11,568 KB
testcase_29 AC 63 ms
11,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int beki(long long a,long long 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;
}


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;
	cin>>N;
	
	long long K;
	cin>>K;
	
	K = mod(K);
	
	int sum = mod(K*(K+1)/2);
	
	combi C(1000000);
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		int t = C.combination(N,i);
		int p = beki(sum,i);
		int x = beki(K,N-i);
		
		t = mod(t * p);
		t = mod(t * x);
		ans = mod(ans + t);
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0