結果

問題 No.1554 array_and_me
ユーザー 👑 Nachia
提出日時 2021-06-18 22:08:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 81,840 KB
最終ジャッジ日時 2025-01-22 09:20:26
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <atcoder/modint>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

using mll = atcoder::static_modint<998244353>;

struct Frac{
  ll b=0, d=1;
};

bool operator<(Frac l, Frac r){ return l.b * r.d < l.d * r.b; }

void testcase(){
  int N,K; cin >> N >> K;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll sumA = 0;
  rep(i,N) sumA += A[i];
  mll ans = 1;
  priority_queue<Frac> Q;
  rep(i,N) Q.push(Frac{ A[i],1 });
  rep(t,K){
    Frac q = Q.top(); Q.pop();
    ans = ans * (t+1) * q.b / q.d / sumA;
    Q.push(Frac{ q.b,q.d+1 });
  }
  cout << ans.val() << "\n";
}


int main(){
  int T; cin >> T;
  while(T--) testcase();
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0