結果

問題 No.1554 array_and_me
ユーザー tktk_snsntktk_snsn
提出日時 2021-06-18 23:32:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 983 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 43,928 KB
最終ジャッジ日時 2023-09-05 00:19:24
合計ジャッジ時間 10,580 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
21,656 KB
testcase_01 AC 1,198 ms
17,940 KB
testcase_02 AC 1,192 ms
18,168 KB
testcase_03 AC 1,174 ms
18,164 KB
testcase_04 AC 1,239 ms
17,856 KB
testcase_05 AC 1,197 ms
17,984 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction
import heapq
from itertools import count
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 998244353
U = 10 ** 5 + 10

fact = [1] * (U+1)
inv = [1] * (U+1)
for i in range(1, U+1):
    fact[i] = fact[i-1] * i % mod
inv[U] = pow(fact[i], mod-2, mod)
for i in reversed(range(U)):
    inv[i] = inv[i+1] * (i + 1) % mod


T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    S = sum(A) % mod
    S_inv = pow(S, mod-2, mod)

    que = [(-Fraction(a), i) for i, a in enumerate(A)]
    heapq.heapify(que)
    cnt = [0] * N
    for _ in range(K):
        f, idx = heapq.heappop(que)
        f = -f
        num, div = f.as_integer_ratio()
        cnt[idx] += 1
        heapq.heappush(que, (-Fraction(num, div + 1), idx))

    res = fact[K]
    for i in range(N):
        res = res * pow(A[i] * S_inv, cnt[i], mod)
        res = res * inv[cnt[i]] % mod
    print(res)
0