結果
問題 | No.1554 array_and_me |
ユーザー |
![]() |
提出日時 | 2021-06-18 22:16:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 1,134 bytes |
コンパイル時間 | 1,862 ms |
コンパイル使用メモリ | 174,264 KB |
実行使用メモリ | 9,728 KB |
最終ジャッジ日時 | 2024-06-22 20:37:28 |
合計ジャッジ時間 | 6,114 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:44:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 44 | auto[s,a,j] = *itr; | ^
ソースコード
#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; } }