結果
| 問題 |
No.1554 array_and_me
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2021-06-18 21:29:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 2,994 bytes |
| コンパイル時間 | 3,478 ms |
| コンパイル使用メモリ | 186,948 KB |
| 最終ジャッジ日時 | 2025-01-22 08:59:11 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 41 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
f[0]=1;
for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
invf[n]=f[n].inv();
for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
if(!(0<=y && y<=x)) return 0;
return f[x]*invf[y]*invf[x-y];
}
struct R{
ll a, b;
R(ll a, ll b):a(b>0 ? a : -a), b(b>0 ? b : -b){}
R(ll a):a(a), b(1){}
R():a(0), b(1){}
R &operator+=(const R &x){
ll a1=a*x.b+b*x.a, b1=b*x.b;
a=a1, b=b1;
return *this;
}
R &operator-=(const R &x){
ll a1=a*x.b-b*x.a, b1=b*x.b;
a=a1, b=b1;
return *this;
}
R &operator*=(const R &x){
a*=x.a, b*=x.b;
return *this;
}
R &operator/=(const R &x){
a*=x.b, b*=x.a;
if(b<0) a=-a, b=-b;
return *this;
}
R operator-() const{
R res(-a, b);
return res;
}
R operator+(const R &x) const{
return R(*this)+=x;
}
R operator-(const R &x) const{
return R(*this)-=x;
}
R operator*(const R &x) const{
return R(*this)*=x;
}
R operator/(const R &x) const{
return R(*this)/=x;
}
bool operator==(const R &x) const{
return a*x.b==b*x.a;
}
bool operator!=(const R &x) const{
return a*x.b!=b*x.a;
}
bool operator<(const R &x) const{
return a*x.b<b*x.a;
}
bool operator>(const R &x) const{
return a*x.b>b*x.a;
}
bool operator<=(const R &x) const{
return a*x.b<=b*x.a;
}
bool operator>=(const R &x) const{
return a*x.b>=b*x.a;
}
};
int main()
{
int t; cin>>t;
fac(100010);
while(t--){
int n, k;
cin>>n>>k;
vector<int> a(n);
int s=0;
for(int i=0; i<n; i++){
cin>>a[i];
s+=a[i];
}
vector<int> nx(n, 1);
priority_queue<pair<R, int>> que;
for(int i=0; i<n; i++){
que.push(make_pair(R(a[i], 1), i));
}
mint ans=f[k]/(mint(s).pow(k));
for(int i=0; i<k; i++){
auto p=que.top(); que.pop();
auto r=p.first;
int t=p.second;
nx[t]++;
ans*=mint(p.first.a)/mint(p.first.b);
que.push(make_pair(R(a[t], nx[t]), t));
}
cout<<ans.val()<<endl;
}
return 0;
}
chocorusk