結果

問題 No.829 成長関数インフレ中
ユーザー 👑 kmjpkmjp
提出日時 2019-05-03 23:56:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 174,704 KB
実行使用メモリ 26,816 KB
最終ジャッジ日時 2023-08-30 07:03:27
合計ジャッジ時間 3,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
17,080 KB
testcase_01 AC 24 ms
17,036 KB
testcase_02 AC 23 ms
17,076 KB
testcase_03 AC 24 ms
17,032 KB
testcase_04 AC 24 ms
17,040 KB
testcase_05 AC 24 ms
17,052 KB
testcase_06 AC 24 ms
17,308 KB
testcase_07 AC 24 ms
17,240 KB
testcase_08 AC 24 ms
17,044 KB
testcase_09 AC 26 ms
17,036 KB
testcase_10 AC 24 ms
17,044 KB
testcase_11 AC 24 ms
17,076 KB
testcase_12 AC 36 ms
17,068 KB
testcase_13 AC 25 ms
17,208 KB
testcase_14 AC 32 ms
17,104 KB
testcase_15 AC 50 ms
19,428 KB
testcase_16 AC 82 ms
21,336 KB
testcase_17 AC 130 ms
23,864 KB
testcase_18 AC 142 ms
25,912 KB
testcase_19 AC 124 ms
24,860 KB
testcase_20 AC 160 ms
26,816 KB
testcase_21 AC 30 ms
17,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,B;
ll mo=1000000007;
vector<int> V;

ll P[202020],Q[202020];
ll L[202020],R[202020];
const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll comb(ll N_, ll C_) {
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>B;
	map<int,int> M;
	FOR(i,N) {
		cin>>x;
		M[x]++;
	}

	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	FORR(v,M) {
		V.push_back(v.second);
	}
	N=V.size();
	int S=0;
	R[N+1]=1;
	for(i=N-1;i>=0;i--) {
		S+=V[i];
		P[i]=comb(S-1,V[i]-1)*fact[V[i]]%mo;
		Q[i]=comb(S-1,V[i])*fact[V[i]]%mo;
		R[i+1]=R[i+2]*(P[i]*B%mo+Q[i])%mo;
	}
	ll ret=0;
	L[0]=1;
	FOR(i,N) {
		L[i+1]=L[i]*(P[i]*B%mo+Q[i])%mo;
		(ret+=L[i]*P[i]%mo*R[i+2])%=mo;
	}
	
	cout<<B*ret%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0