結果

問題 No.1554 array_and_me
ユーザー shotoyooshotoyoo
提出日時 2021-05-16 11:25:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 673 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 97,672 KB
最終ジャッジ日時 2023-09-04 22:09:25
合計ジャッジ時間 21,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,712 KB
testcase_01 AC 337 ms
82,140 KB
testcase_02 AC 335 ms
81,988 KB
testcase_03 AC 337 ms
81,992 KB
testcase_04 AC 343 ms
81,724 KB
testcase_05 AC 345 ms
82,060 KB
testcase_06 AC 623 ms
97,296 KB
testcase_07 AC 621 ms
96,240 KB
testcase_08 AC 597 ms
96,376 KB
testcase_09 AC 625 ms
96,744 KB
testcase_10 AC 628 ms
97,672 KB
testcase_11 AC 180 ms
93,436 KB
testcase_12 AC 178 ms
93,628 KB
testcase_13 AC 179 ms
93,520 KB
testcase_14 AC 183 ms
93,368 KB
testcase_15 AC 181 ms
93,376 KB
testcase_16 AC 208 ms
79,444 KB
testcase_17 AC 209 ms
79,452 KB
testcase_18 AC 210 ms
79,548 KB
testcase_19 AC 223 ms
79,348 KB
testcase_20 AC 222 ms
79,496 KB
testcase_21 AC 559 ms
85,740 KB
testcase_22 AC 541 ms
85,108 KB
testcase_23 AC 558 ms
84,232 KB
testcase_24 AC 550 ms
85,092 KB
testcase_25 AC 539 ms
84,532 KB
testcase_26 AC 636 ms
92,620 KB
testcase_27 AC 650 ms
92,868 KB
testcase_28 AC 642 ms
92,680 KB
testcase_29 AC 640 ms
92,416 KB
testcase_30 AC 646 ms
92,272 KB
testcase_31 AC 637 ms
92,432 KB
testcase_32 AC 666 ms
92,688 KB
testcase_33 AC 659 ms
93,692 KB
testcase_34 AC 647 ms
92,104 KB
testcase_35 AC 673 ms
93,092 KB
testcase_36 AC 397 ms
89,748 KB
testcase_37 AC 397 ms
89,900 KB
testcase_38 AC 438 ms
89,820 KB
testcase_39 AC 437 ms
90,524 KB
testcase_40 AC 463 ms
91,808 KB
testcase_41 AC 358 ms
81,352 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 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