結果

問題 No.1554 array_and_me
ユーザー 李凯麟李凯麟
提出日時 2021-07-12 23:13:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 170,304 KB
実行使用メモリ 5,736 KB
最終ジャッジ日時 2023-09-14 20:46:29
合計ジャッジ時間 5,077 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 30 ms
4,380 KB
testcase_02 AC 30 ms
4,380 KB
testcase_03 AC 30 ms
4,380 KB
testcase_04 AC 30 ms
4,380 KB
testcase_05 AC 31 ms
4,376 KB
testcase_06 AC 79 ms
5,712 KB
testcase_07 AC 79 ms
5,704 KB
testcase_08 AC 79 ms
5,580 KB
testcase_09 AC 79 ms
5,736 KB
testcase_10 AC 79 ms
5,576 KB
testcase_11 AC 13 ms
5,660 KB
testcase_12 AC 14 ms
5,576 KB
testcase_13 AC 13 ms
5,576 KB
testcase_14 AC 13 ms
5,700 KB
testcase_15 AC 14 ms
5,576 KB
testcase_16 AC 34 ms
4,376 KB
testcase_17 AC 34 ms
4,380 KB
testcase_18 AC 34 ms
4,376 KB
testcase_19 AC 34 ms
4,380 KB
testcase_20 AC 33 ms
4,376 KB
testcase_21 AC 48 ms
4,380 KB
testcase_22 AC 46 ms
4,376 KB
testcase_23 AC 47 ms
4,380 KB
testcase_24 AC 47 ms
4,376 KB
testcase_25 AC 47 ms
4,376 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 56 ms
4,376 KB
testcase_28 AC 56 ms
4,380 KB
testcase_29 AC 56 ms
4,376 KB
testcase_30 AC 57 ms
4,376 KB
testcase_31 AC 55 ms
4,376 KB
testcase_32 AC 56 ms
4,376 KB
testcase_33 AC 56 ms
4,376 KB
testcase_34 AC 55 ms
4,376 KB
testcase_35 AC 57 ms
4,380 KB
testcase_36 AC 50 ms
4,380 KB
testcase_37 AC 50 ms
4,376 KB
testcase_38 AC 50 ms
4,380 KB
testcase_39 AC 50 ms
4,380 KB
testcase_40 AC 49 ms
4,376 KB
testcase_41 AC 42 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
#define pb push_back
#define lowbit(x) x & -x
#define int long long
const int N=2e5+7;
const int mod=998244353;
ll quick(ll x, ll y) {
	ll res=1;
	while(y) {
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
} 
int t,n,k;
int a[101010];
int X[101010];
void solve() {
	auto cmp = [](int L,int R) {
		return 1LL*a[L]*(X[R]+1)<1LL*a[R]*(X[L]+1);
	};
	priority_queue<int,vector<int>,decltype(cmp)> pq(cmp);
	cin>>n>>k;
	ll s=0;
	for(int i=0;i<n;++i) {
		cin>>a[i];
		s+=a[i];
		X[i]=0;
		pq.push(i);
	}
	ll ans=1;
	for(int i=0;i<k;++i) {
		int x=pq.top();
		pq.pop();
		X[x]++;
		ans=ans*(1+i)%mod;
		ans=ans*quick(X[x],mod-2)%mod;
		ans=ans*a[x]%mod;
		ans=ans*quick(s,mod-2)%mod;
		pq.push(x);
	}
	print(ans);
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin>>t;
	while(t--)  solve();
}
0