結果

問題 No.1554 array_and_me
ユーザー tktk_snsntktk_snsn
提出日時 2021-06-18 23:33:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 955 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 134,120 KB
最終ジャッジ日時 2023-09-05 00:20:19
合計ジャッジ時間 44,851 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
91,932 KB
testcase_01 AC 797 ms
98,276 KB
testcase_02 AC 822 ms
102,504 KB
testcase_03 AC 794 ms
101,900 KB
testcase_04 AC 804 ms
102,568 KB
testcase_05 AC 804 ms
102,396 KB
testcase_06 WA -
testcase_07 AC 1,559 ms
132,224 KB
testcase_08 AC 1,564 ms
132,304 KB
testcase_09 AC 1,565 ms
134,120 KB
testcase_10 AC 1,554 ms
128,532 KB
testcase_11 AC 504 ms
114,500 KB
testcase_12 AC 510 ms
114,884 KB
testcase_13 AC 518 ms
114,544 KB
testcase_14 AC 505 ms
114,480 KB
testcase_15 AC 510 ms
114,328 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1,173 ms
125,840 KB
testcase_37 AC 1,151 ms
124,896 KB
testcase_38 AC 1,154 ms
128,788 KB
testcase_39 AC 1,142 ms
126,440 KB
testcase_40 AC 1,129 ms
125,444 KB
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction
import heapq
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