結果

問題 No.1554 array_and_me
ユーザー 01fe18bcs175 rohan01fe18bcs175 rohan
提出日時 2021-06-18 23:47:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 173,148 KB
実行使用メモリ 9,880 KB
最終ジャッジ日時 2023-09-05 00:25:48
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 47 ms
4,380 KB
testcase_02 AC 47 ms
4,376 KB
testcase_03 AC 47 ms
4,376 KB
testcase_04 AC 47 ms
4,376 KB
testcase_05 AC 47 ms
4,380 KB
testcase_06 AC 126 ms
9,644 KB
testcase_07 AC 126 ms
9,880 KB
testcase_08 AC 125 ms
9,612 KB
testcase_09 AC 125 ms
9,796 KB
testcase_10 AC 130 ms
9,584 KB
testcase_11 AC 65 ms
9,588 KB
testcase_12 AC 66 ms
9,660 KB
testcase_13 AC 66 ms
9,784 KB
testcase_14 AC 66 ms
9,584 KB
testcase_15 AC 66 ms
9,672 KB
testcase_16 AC 44 ms
4,376 KB
testcase_17 AC 44 ms
4,380 KB
testcase_18 AC 44 ms
4,388 KB
testcase_19 AC 43 ms
4,376 KB
testcase_20 AC 45 ms
4,380 KB
testcase_21 AC 83 ms
4,380 KB
testcase_22 AC 83 ms
4,380 KB
testcase_23 AC 83 ms
4,380 KB
testcase_24 AC 83 ms
4,376 KB
testcase_25 AC 84 ms
4,380 KB
testcase_26 AC 96 ms
4,380 KB
testcase_27 AC 95 ms
4,376 KB
testcase_28 AC 95 ms
4,380 KB
testcase_29 AC 96 ms
4,380 KB
testcase_30 AC 101 ms
4,380 KB
testcase_31 AC 98 ms
4,376 KB
testcase_32 AC 97 ms
4,376 KB
testcase_33 AC 96 ms
4,380 KB
testcase_34 AC 96 ms
4,380 KB
testcase_35 AC 96 ms
4,380 KB
testcase_36 AC 88 ms
4,380 KB
testcase_37 AC 87 ms
4,380 KB
testcase_38 AC 88 ms
4,380 KB
testcase_39 AC 92 ms
4,380 KB
testcase_40 AC 88 ms
4,376 KB
testcase_41 AC 60 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:44:13: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   44 |         auto[s,a,j] = *itr;
      |             ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;

ll mod = 998244353;


//mod逆元
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    ll T; cin >> T;
    rep(i,T){
    ll N,K; cin >> N >> K;
    ll sum = 0;
    multiset<tuple<double,ll,ll>> num;
    rep(i,N){
        ll a; cin >> a;
        num.insert(make_tuple((double)a,a,1LL));
        sum += a;
    }
    sum %= mod;
    ll ans = 1;
    rep(i,K){
        ans *= (ll)(i+1); ans %= mod;
        ans *= modinv(sum,mod); ans %= mod;
    }
    rep(i,K){
        auto itr = num.end(); itr--;
        auto[s,a,j] = *itr;
        num.erase(itr);
        ans *= a; ans %= mod;
        ans *= modinv(j,mod); ans %= mod;
        num.insert(make_tuple(s*(double)(j)/(double)(j+1),a,j+1));
    }
    cout << ans << endl;
    }
}
0