結果

問題 No.1554 array_and_me
ユーザー shotoyooshotoyoo
提出日時 2021-05-03 07:43:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 672 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 102,928 KB
最終ジャッジ日時 2023-09-04 22:04:37
合計ジャッジ時間 20,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,640 KB
testcase_01 AC 338 ms
81,284 KB
testcase_02 AC 335 ms
81,856 KB
testcase_03 AC 337 ms
82,076 KB
testcase_04 AC 335 ms
80,880 KB
testcase_05 AC 339 ms
81,672 KB
testcase_06 AC 612 ms
102,856 KB
testcase_07 AC 616 ms
102,928 KB
testcase_08 AC 600 ms
102,772 KB
testcase_09 AC 627 ms
102,844 KB
testcase_10 AC 619 ms
102,828 KB
testcase_11 AC 179 ms
100,064 KB
testcase_12 AC 181 ms
100,080 KB
testcase_13 AC 181 ms
99,988 KB
testcase_14 AC 185 ms
99,828 KB
testcase_15 AC 180 ms
99,948 KB
testcase_16 AC 206 ms
79,372 KB
testcase_17 AC 208 ms
79,364 KB
testcase_18 AC 205 ms
79,900 KB
testcase_19 AC 220 ms
79,404 KB
testcase_20 AC 218 ms
79,552 KB
testcase_21 AC 548 ms
85,300 KB
testcase_22 AC 537 ms
83,692 KB
testcase_23 AC 542 ms
84,800 KB
testcase_24 AC 542 ms
84,660 KB
testcase_25 AC 540 ms
84,404 KB
testcase_26 AC 639 ms
93,360 KB
testcase_27 AC 641 ms
91,892 KB
testcase_28 AC 640 ms
93,404 KB
testcase_29 AC 640 ms
92,804 KB
testcase_30 AC 655 ms
91,788 KB
testcase_31 AC 656 ms
92,680 KB
testcase_32 AC 661 ms
92,584 KB
testcase_33 AC 667 ms
92,836 KB
testcase_34 AC 658 ms
93,116 KB
testcase_35 AC 672 ms
93,308 KB
testcase_36 AC 396 ms
90,192 KB
testcase_37 AC 402 ms
89,780 KB
testcase_38 AC 444 ms
90,032 KB
testcase_39 AC 437 ms
91,220 KB
testcase_40 AC 454 ms
91,620 KB
testcase_41 AC 352 ms
81,124 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
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))
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