結果

問題 No.1554 array_and_me
ユーザー Kiri8128Kiri8128
提出日時 2021-06-18 23:07:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 97,388 KB
最終ジャッジ日時 2023-09-05 00:06:52
合計ジャッジ時間 13,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
79,028 KB
testcase_01 AC 239 ms
82,748 KB
testcase_02 AC 236 ms
82,196 KB
testcase_03 AC 238 ms
82,432 KB
testcase_04 AC 239 ms
82,504 KB
testcase_05 AC 240 ms
82,020 KB
testcase_06 AC 400 ms
97,388 KB
testcase_07 AC 390 ms
96,164 KB
testcase_08 AC 398 ms
97,116 KB
testcase_09 AC 390 ms
95,432 KB
testcase_10 AC 386 ms
97,112 KB
testcase_11 AC 162 ms
90,196 KB
testcase_12 AC 161 ms
92,736 KB
testcase_13 AC 161 ms
90,492 KB
testcase_14 AC 165 ms
92,712 KB
testcase_15 AC 160 ms
92,820 KB
testcase_16 AC 88 ms
79,308 KB
testcase_17 AC 89 ms
79,036 KB
testcase_18 AC 91 ms
79,112 KB
testcase_19 AC 88 ms
78,988 KB
testcase_20 AC 88 ms
79,028 KB
testcase_21 AC 303 ms
84,308 KB
testcase_22 AC 299 ms
83,880 KB
testcase_23 AC 299 ms
83,312 KB
testcase_24 AC 308 ms
84,500 KB
testcase_25 AC 268 ms
82,988 KB
testcase_26 AC 338 ms
92,584 KB
testcase_27 AC 393 ms
93,792 KB
testcase_28 AC 383 ms
92,688 KB
testcase_29 AC 347 ms
92,608 KB
testcase_30 AC 356 ms
91,660 KB
testcase_31 AC 364 ms
92,364 KB
testcase_32 AC 399 ms
93,128 KB
testcase_33 AC 400 ms
93,560 KB
testcase_34 AC 358 ms
92,616 KB
testcase_35 AC 360 ms
92,680 KB
testcase_36 AC 343 ms
90,996 KB
testcase_37 AC 345 ms
92,944 KB
testcase_38 AC 326 ms
91,556 KB
testcase_39 AC 340 ms
91,240 KB
testcase_40 AC 350 ms
90,276 KB
testcase_41 AC 236 ms
82,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
P = 998244353
nn = 202020

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0

T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    su = sum(A)
    B = [max(K * a // su - 1, 0) for a in A]
    su2 = sum(B)
    
    H = []
    for i in range(N):
        heappush(H, (-A[i] / (B[i] + 1), i))
    for k in range(K - su2):
        a, i = heappop(H)
        B[i] += 1
        heappush(H, (-A[i] / (B[i] + 1), i))

    ans = fa[K]
    for i, b in enumerate(B):
        ans = ans * fainv[b] % P * pow(A[i], b, P) % P
    ans = ans * pow(su, (P - 2) * K, P) % P
    print(ans)
0