結果

問題 No.1554 array_and_me
ユーザー shotoyooshotoyoo
提出日時 2021-05-16 11:27:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 653 ms / 2,000 ms
コード長 1,446 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 97,128 KB
最終ジャッジ日時 2023-09-04 22:09:48
合計ジャッジ時間 20,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,192 KB
testcase_01 AC 341 ms
81,988 KB
testcase_02 AC 336 ms
81,496 KB
testcase_03 AC 330 ms
81,940 KB
testcase_04 AC 334 ms
81,608 KB
testcase_05 AC 333 ms
81,824 KB
testcase_06 AC 588 ms
96,956 KB
testcase_07 AC 584 ms
95,956 KB
testcase_08 AC 571 ms
96,024 KB
testcase_09 AC 594 ms
96,484 KB
testcase_10 AC 619 ms
97,128 KB
testcase_11 AC 179 ms
92,976 KB
testcase_12 AC 177 ms
93,312 KB
testcase_13 AC 176 ms
93,320 KB
testcase_14 AC 178 ms
93,048 KB
testcase_15 AC 178 ms
92,984 KB
testcase_16 AC 206 ms
79,092 KB
testcase_17 AC 201 ms
79,100 KB
testcase_18 AC 198 ms
79,296 KB
testcase_19 AC 210 ms
79,076 KB
testcase_20 AC 207 ms
79,188 KB
testcase_21 AC 528 ms
85,328 KB
testcase_22 AC 518 ms
84,600 KB
testcase_23 AC 530 ms
83,912 KB
testcase_24 AC 530 ms
84,760 KB
testcase_25 AC 529 ms
84,480 KB
testcase_26 AC 628 ms
92,196 KB
testcase_27 AC 645 ms
92,608 KB
testcase_28 AC 637 ms
92,056 KB
testcase_29 AC 644 ms
92,164 KB
testcase_30 AC 639 ms
91,860 KB
testcase_31 AC 629 ms
92,424 KB
testcase_32 AC 640 ms
92,292 KB
testcase_33 AC 653 ms
93,416 KB
testcase_34 AC 632 ms
92,752 KB
testcase_35 AC 653 ms
92,740 KB
testcase_36 AC 391 ms
89,408 KB
testcase_37 AC 388 ms
89,436 KB
testcase_38 AC 431 ms
89,804 KB
testcase_39 AC 426 ms
90,284 KB
testcase_40 AC 446 ms
91,432 KB
testcase_41 AC 347 ms
81,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")

t = int(input())
items = []
N = 100
M = 998244353
sn = sk = 0
for _ in range(t):
    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    N = max(N, n+k+10)
    items.append((n,k,a))
    sn += n
    sk += k
    assert all(1<=v<=1000 for v in a)
    assert 1<=n<=10**5
    assert 1<=k<=10**5
assert 1<=t<=100
assert sn<=10**5
assert sk<=10**5

g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1]
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
    
ans = []
for n,k,a in items:
    from heapq import heappop as hpp, heappush as hp, heapify
    h = [(-v,i) for i,v in enumerate(a)]
    heapify(h)
    x = [0]*n
    for _ in range(k):
        v,i = hpp(h)
        v *= -1
        x[i] += 1
        hp(h, (-a[i]/(x[i]+1), i))
    val = g1[k]
    for i in range(n):
        val *= (pow(a[i], x[i], M) * g2[x[i]] % M)
        val %= M
    val *= pow(pow(sum(a), k, M), M-2, M)
    ans.append(val%M)
write("\n".join(map(str, ans)))
0