結果

問題 No.1554 array_and_me
ユーザー optopt
提出日時 2021-06-18 21:41:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 4,526 ms
コンパイル使用メモリ 267,600 KB
実行使用メモリ 10,456 KB
最終ジャッジ日時 2023-09-04 22:37:48
合計ジャッジ時間 7,890 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 25 ms
4,376 KB
testcase_02 AC 25 ms
4,380 KB
testcase_03 AC 24 ms
4,376 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 25 ms
4,380 KB
testcase_06 AC 65 ms
10,232 KB
testcase_07 AC 65 ms
9,672 KB
testcase_08 AC 64 ms
9,160 KB
testcase_09 AC 64 ms
10,456 KB
testcase_10 AC 64 ms
9,136 KB
testcase_11 AC 29 ms
7,936 KB
testcase_12 AC 29 ms
9,176 KB
testcase_13 AC 30 ms
9,292 KB
testcase_14 AC 29 ms
8,748 KB
testcase_15 AC 29 ms
8,452 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 42 ms
4,376 KB
testcase_23 AC 43 ms
4,376 KB
testcase_24 AC 43 ms
4,376 KB
testcase_25 AC 43 ms
4,380 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 53 ms
4,376 KB
testcase_28 AC 53 ms
4,380 KB
testcase_29 AC 53 ms
4,376 KB
testcase_30 AC 53 ms
4,376 KB
testcase_31 AC 53 ms
4,380 KB
testcase_32 AC 53 ms
4,376 KB
testcase_33 AC 53 ms
4,376 KB
testcase_34 AC 53 ms
4,376 KB
testcase_35 AC 53 ms
4,376 KB
testcase_36 AC 52 ms
4,380 KB
testcase_37 AC 52 ms
4,380 KB
testcase_38 AC 52 ms
4,376 KB
testcase_39 AC 52 ms
4,376 KB
testcase_40 AC 52 ms
4,380 KB
testcase_41 AC 28 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
#define rep_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define drep_(i, a_, b_, a, b, ...) for (int i = (a)-1, lim##i = (b); i >= lim##i; --i)
#define drep(i, ...) drep_(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define all(x) (x).begin(), (x).end()
template<class T> using V = vector<T>;
using ld = long double;
using Vi = V<int>;
using mint = modint998244353;


// O(m + log mod)
// only for mod > m
template<class T> struct factorial {
private:
  int MAX;
  vector<T> _fac, _invf;
public:
  factorial(int m = -1) {
    if (m < 0) return;
    MAX = m; _fac.assign(m+1, 1); _invf.assign(m+1, 1);
    rep(i, 2, m+1) _fac[i] = _fac[i-1] * i;
    _invf[m] /= _fac[m];
    drep(i, m+1, 3) _invf[i-1] = _invf[i] * i;
  }
  T fac(int n) const { return _fac[n]; }
  T inv_fac(int n) const { return _invf[n]; }
};


int solve() {
  int n, k; cin >> n >> k;
  factorial<mint> fc(k);
  Vi a(n); for (auto &e : a) cin >> e;
  int S = accumulate(all(a), 0);

  priority_queue<pair<ld, int>> pq;
  rep(i, n) pq.emplace(ld(a[i]) / S, i);

  Vi x(n);
  rep(_, k) {
    auto [z, i] = pq.top(); pq.pop();
    x[i]++;
    pq.emplace(ld(a[i]) / S / (x[i]+1), i);
  }

  mint ans = fc.fac(k) / mint(S).pow(k);
  rep(i, n) {
    ans *= mint(a[i]).pow(x[i]);
    ans *= fc.inv_fac(x[i]);
  }
  return ans.val();
}


int main() {
  int t; cin >> t;
  rep(i, t) cout << solve() << '\n';
}
0