結果

問題 No.1554 array_and_me
ユーザー rianoriano
提出日時 2021-06-18 22:16:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 172,084 KB
実行使用メモリ 9,660 KB
最終ジャッジ日時 2023-09-04 23:21:43
合計ジャッジ時間 6,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 46 ms
4,376 KB
testcase_02 AC 47 ms
4,380 KB
testcase_03 AC 47 ms
4,380 KB
testcase_04 AC 48 ms
4,376 KB
testcase_05 AC 48 ms
4,376 KB
testcase_06 AC 125 ms
9,620 KB
testcase_07 AC 124 ms
9,564 KB
testcase_08 AC 124 ms
9,592 KB
testcase_09 AC 125 ms
9,604 KB
testcase_10 AC 128 ms
9,660 KB
testcase_11 AC 66 ms
9,600 KB
testcase_12 AC 65 ms
9,596 KB
testcase_13 AC 64 ms
9,616 KB
testcase_14 AC 66 ms
9,604 KB
testcase_15 AC 64 ms
9,648 KB
testcase_16 AC 44 ms
4,380 KB
testcase_17 AC 44 ms
4,380 KB
testcase_18 AC 44 ms
4,380 KB
testcase_19 AC 43 ms
4,380 KB
testcase_20 AC 45 ms
4,376 KB
testcase_21 AC 84 ms
4,380 KB
testcase_22 AC 85 ms
4,376 KB
testcase_23 AC 83 ms
4,380 KB
testcase_24 AC 84 ms
4,380 KB
testcase_25 AC 84 ms
4,384 KB
testcase_26 AC 97 ms
4,380 KB
testcase_27 AC 94 ms
4,376 KB
testcase_28 AC 96 ms
4,380 KB
testcase_29 AC 96 ms
4,376 KB
testcase_30 AC 97 ms
4,380 KB
testcase_31 AC 97 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,376 KB
testcase_36 AC 89 ms
4,380 KB
testcase_37 AC 87 ms
4,380 KB
testcase_38 AC 89 ms
4,376 KB
testcase_39 AC 90 ms
4,504 KB
testcase_40 AC 88 ms
4,380 KB
testcase_41 AC 61 ms
4,376 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