結果

問題 No.1554 array_and_me
ユーザー 沙耶花沙耶花
提出日時 2021-06-18 22:20:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,535 bytes
コンパイル時間 5,737 ms
コンパイル使用メモリ 269,320 KB
実行使用メモリ 14,284 KB
最終ジャッジ日時 2023-09-04 23:31:18
合計ジャッジ時間 9,055 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
11,448 KB
testcase_01 AC 46 ms
11,612 KB
testcase_02 AC 46 ms
11,488 KB
testcase_03 AC 46 ms
11,488 KB
testcase_04 AC 47 ms
11,480 KB
testcase_05 AC 47 ms
11,508 KB
testcase_06 AC 82 ms
14,232 KB
testcase_07 AC 82 ms
14,280 KB
testcase_08 AC 82 ms
14,260 KB
testcase_09 AC 82 ms
14,084 KB
testcase_10 AC 82 ms
14,088 KB
testcase_11 AC 60 ms
14,212 KB
testcase_12 AC 60 ms
14,144 KB
testcase_13 AC 60 ms
14,284 KB
testcase_14 AC 60 ms
14,260 KB
testcase_15 AC 60 ms
14,272 KB
testcase_16 AC 26 ms
11,448 KB
testcase_17 AC 25 ms
11,456 KB
testcase_18 AC 25 ms
11,736 KB
testcase_19 AC 25 ms
11,464 KB
testcase_20 AC 26 ms
11,516 KB
testcase_21 AC 70 ms
11,748 KB
testcase_22 AC 69 ms
11,664 KB
testcase_23 AC 69 ms
11,480 KB
testcase_24 AC 69 ms
11,604 KB
testcase_25 AC 69 ms
11,628 KB
testcase_26 AC 74 ms
11,796 KB
testcase_27 AC 75 ms
11,920 KB
testcase_28 AC 75 ms
11,984 KB
testcase_29 AC 75 ms
11,880 KB
testcase_30 AC 77 ms
11,900 KB
testcase_31 AC 75 ms
11,872 KB
testcase_32 AC 75 ms
11,816 KB
testcase_33 AC 75 ms
12,000 KB
testcase_34 AC 75 ms
11,904 KB
testcase_35 AC 75 ms
11,788 KB
testcase_36 AC 75 ms
11,864 KB
testcase_37 AC 74 ms
11,980 KB
testcase_38 AC 74 ms
11,936 KB
testcase_39 AC 74 ms
11,868 KB
testcase_40 AC 75 ms
11,852 KB
testcase_41 AC 49 ms
11,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

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

combi C(1000000);

void solve(){
	int N,K;
	cin>>N>>K;
	
	vector<int> A(N);
	int S = 0;
	rep(i,N){
		cin>>A[i];
		S += A[i];
	}
	
	vector<int> v(N,0);
	
	priority_queue<pair<double,pair<int,int>>> Q;
	
	rep(i,N){
		double t = A[i];
		t /= S;
		Q.emplace(t,make_pair(i,1));
	}
	
	rep(_,K){
		auto t = Q.top();
		Q.pop();
		v[t.second.first] ++;
		t.second.second ++;
		t.first = A[t.second.first];
		t.first /= S;
		t.first /= t.second.second;
		Q.push(t);
	}
	
	mint ans = 1;
	
	int n = K;
	rep(i,N){
		//cout<<v[i]<<',';
		mint p = A[i];
		p /= S;
		ans *= p.pow(v[i]);
		ans *= C.combination(n,v[i]);
		n -= v[i];
	}
	
	
	cout<<ans.val()<<endl;
	
}

int main(){
	
	int _T;
	cin>>_T;
	
	rep(_,_T){
		solve();
	}
	
	return 0;
}
0