結果

問題 No.1554 array_and_me
ユーザー chocoruskchocorusk
提出日時 2021-06-18 21:29:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,994 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 193,156 KB
実行使用メモリ 23,880 KB
最終ジャッジ日時 2023-09-04 22:27:12
合計ジャッジ時間 7,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
19,328 KB
testcase_01 AC 37 ms
19,120 KB
testcase_02 AC 37 ms
19,092 KB
testcase_03 AC 38 ms
19,100 KB
testcase_04 AC 38 ms
19,132 KB
testcase_05 AC 38 ms
19,096 KB
testcase_06 AC 78 ms
22,768 KB
testcase_07 AC 78 ms
22,756 KB
testcase_08 AC 77 ms
22,676 KB
testcase_09 AC 79 ms
22,636 KB
testcase_10 AC 77 ms
22,760 KB
testcase_11 AC 34 ms
22,580 KB
testcase_12 AC 33 ms
22,932 KB
testcase_13 AC 33 ms
23,744 KB
testcase_14 AC 33 ms
23,880 KB
testcase_15 AC 34 ms
22,748 KB
testcase_16 AC 29 ms
19,016 KB
testcase_17 AC 28 ms
19,040 KB
testcase_18 AC 28 ms
19,092 KB
testcase_19 AC 28 ms
19,092 KB
testcase_20 AC 28 ms
19,020 KB
testcase_21 AC 56 ms
19,064 KB
testcase_22 AC 56 ms
19,196 KB
testcase_23 AC 56 ms
19,256 KB
testcase_24 AC 57 ms
19,052 KB
testcase_25 AC 56 ms
19,212 KB
testcase_26 AC 66 ms
19,448 KB
testcase_27 AC 64 ms
19,400 KB
testcase_28 AC 65 ms
19,472 KB
testcase_29 AC 65 ms
19,408 KB
testcase_30 AC 65 ms
19,448 KB
testcase_31 AC 65 ms
19,408 KB
testcase_32 AC 65 ms
19,400 KB
testcase_33 AC 65 ms
19,456 KB
testcase_34 AC 65 ms
19,408 KB
testcase_35 AC 65 ms
19,324 KB
testcase_36 AC 65 ms
19,356 KB
testcase_37 AC 65 ms
19,464 KB
testcase_38 AC 65 ms
19,408 KB
testcase_39 AC 65 ms
19,412 KB
testcase_40 AC 65 ms
19,468 KB
testcase_41 AC 44 ms
19,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0