結果

問題 No.1554 array_and_me
ユーザー mkawa2mkawa2
提出日時 2023-11-07 15:21:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,541 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 81,896 KB
実行使用メモリ 125,072 KB
最終ジャッジ日時 2023-11-07 15:22:06
合計ジャッジ時間 46,230 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
100,624 KB
testcase_01 AC 783 ms
102,416 KB
testcase_02 AC 773 ms
101,648 KB
testcase_03 AC 745 ms
101,888 KB
testcase_04 AC 774 ms
102,032 KB
testcase_05 AC 750 ms
102,160 KB
testcase_06 AC 1,521 ms
125,072 KB
testcase_07 AC 1,500 ms
125,072 KB
testcase_08 AC 1,494 ms
124,944 KB
testcase_09 AC 1,513 ms
125,072 KB
testcase_10 AC 1,541 ms
124,936 KB
testcase_11 AC 424 ms
125,072 KB
testcase_12 AC 405 ms
125,072 KB
testcase_13 AC 417 ms
125,072 KB
testcase_14 AC 416 ms
124,932 KB
testcase_15 AC 442 ms
125,072 KB
testcase_16 AC 603 ms
102,156 KB
testcase_17 AC 669 ms
101,904 KB
testcase_18 AC 610 ms
101,520 KB
testcase_19 AC 631 ms
102,156 KB
testcase_20 AC 610 ms
101,520 KB
testcase_21 AC 1,028 ms
102,288 KB
testcase_22 AC 1,073 ms
102,160 KB
testcase_23 AC 1,043 ms
102,544 KB
testcase_24 AC 1,032 ms
101,648 KB
testcase_25 AC 1,043 ms
102,672 KB
testcase_26 AC 1,372 ms
122,924 KB
testcase_27 AC 1,371 ms
121,380 KB
testcase_28 AC 1,392 ms
121,012 KB
testcase_29 AC 1,378 ms
121,752 KB
testcase_30 AC 1,375 ms
121,056 KB
testcase_31 AC 1,415 ms
122,416 KB
testcase_32 AC 1,374 ms
120,640 KB
testcase_33 AC 1,350 ms
122,684 KB
testcase_34 AC 1,350 ms
122,144 KB
testcase_35 AC 1,378 ms
122,536 KB
testcase_36 AC 1,150 ms
121,656 KB
testcase_37 AC 1,148 ms
120,616 KB
testcase_38 AC 1,139 ms
120,744 KB
testcase_39 AC 1,159 ms
120,228 KB
testcase_40 AC 1,144 ms
121,016 KB
testcase_41 AC 953 ms
102,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

from heapq import *
from fractions import Fraction

def inv_arr(n):
    if n < 1: return []
    res = [-1, 1]
    for i in range(2, n+1):
        res.append(res[md%i]*(md-md//i)%md)
    return res

inv=inv_arr(100005)

n_max = 100005
fac = [1]
for i in range(1, n_max+1): fac.append(fac[-1]*i%md)
ifac = [1]*(n_max+1)
ifac[n_max] = pow(fac[n_max], md-2, md)
for i in range(n_max-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%md

def solve():
    n,k=LI()
    aa=LI()
    xx=[1]*n
    ans=fac[k]*pow(sum(aa),(md-2)*k,md)%md
    hp=[(Fraction(1,a),i) for i,a in enumerate(aa)]
    heapify(hp)
    for _ in range(k):
        f,i=heappop(hp)
        x,a=xx[i],aa[i]
        ans*=a*inv[x]%md
        ans%=md
        heappush(hp,(Fraction(x+1,a),i))
        xx[i] += 1
    print(ans)

for _ in range(II()):solve()
0