結果

問題 No.1554 array_and_me
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-06-19 15:08:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 853 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 109,768 KB
最終ジャッジ日時 2023-09-05 00:53:53
合計ジャッジ時間 23,733 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
94,936 KB
testcase_01 AC 342 ms
95,572 KB
testcase_02 AC 321 ms
95,716 KB
testcase_03 AC 320 ms
96,172 KB
testcase_04 AC 316 ms
95,360 KB
testcase_05 AC 311 ms
95,792 KB
testcase_06 AC 835 ms
109,408 KB
testcase_07 AC 842 ms
109,392 KB
testcase_08 AC 852 ms
109,528 KB
testcase_09 AC 853 ms
109,420 KB
testcase_10 AC 838 ms
109,368 KB
testcase_11 AC 193 ms
109,600 KB
testcase_12 AC 194 ms
109,412 KB
testcase_13 AC 193 ms
109,596 KB
testcase_14 AC 193 ms
109,768 KB
testcase_15 AC 195 ms
109,468 KB
testcase_16 AC 220 ms
96,360 KB
testcase_17 AC 220 ms
96,956 KB
testcase_18 AC 217 ms
96,800 KB
testcase_19 AC 229 ms
96,708 KB
testcase_20 AC 232 ms
96,776 KB
testcase_21 AC 507 ms
95,852 KB
testcase_22 AC 507 ms
95,668 KB
testcase_23 AC 509 ms
96,036 KB
testcase_24 AC 501 ms
95,364 KB
testcase_25 AC 503 ms
95,980 KB
testcase_26 AC 664 ms
100,384 KB
testcase_27 AC 680 ms
101,328 KB
testcase_28 AC 677 ms
100,316 KB
testcase_29 AC 685 ms
100,136 KB
testcase_30 AC 668 ms
100,868 KB
testcase_31 AC 662 ms
100,832 KB
testcase_32 AC 677 ms
100,472 KB
testcase_33 AC 690 ms
100,572 KB
testcase_34 AC 674 ms
98,764 KB
testcase_35 AC 703 ms
101,824 KB
testcase_36 AC 498 ms
99,084 KB
testcase_37 AC 494 ms
98,656 KB
testcase_38 AC 499 ms
98,308 KB
testcase_39 AC 480 ms
97,780 KB
testcase_40 AC 493 ms
98,760 KB
testcase_41 AC 358 ms
95,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
mod = 998244353
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,10**5+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
def solve():
    n,k = map(int,input().split())
    A = list(map(int,input().split()))
    X = [0]*n
    h = [[-a,i] for i,a in enumerate(A)]
    heapify(h)
    for _ in range(k):
        v,i = heappop(h)
        X[i] += 1
        heappush(h,[-A[i]/(X[i]+1),i])
    
    ans = fact[k]
    for i,(x,a) in enumerate(zip(X,A)):
        ans *= pow(a,x,mod)*finv[x]%mod
        ans %= mod
    base = pow(sum(A),k,mod)
    ans *= pow(base,mod-2,mod)
    ans %= mod
    print(ans)

t = int(input())
for _ in range(t):
    solve()

0