結果

問題 No.1554 array_and_me
ユーザー tktk_snsntktk_snsn
提出日時 2021-06-18 23:37:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,039 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 133,096 KB
最終ジャッジ日時 2023-09-05 00:22:45
合計ジャッジ時間 44,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
92,148 KB
testcase_01 AC 819 ms
103,324 KB
testcase_02 AC 794 ms
100,160 KB
testcase_03 AC 821 ms
100,212 KB
testcase_04 AC 794 ms
103,244 KB
testcase_05 AC 830 ms
102,564 KB
testcase_06 WA -
testcase_07 AC 1,571 ms
131,972 KB
testcase_08 AC 1,599 ms
131,084 KB
testcase_09 AC 1,591 ms
132,300 KB
testcase_10 AC 1,562 ms
130,076 KB
testcase_11 AC 517 ms
114,488 KB
testcase_12 AC 517 ms
114,544 KB
testcase_13 AC 515 ms
114,652 KB
testcase_14 AC 513 ms
114,632 KB
testcase_15 AC 516 ms
114,740 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,171 ms
128,132 KB
testcase_37 AC 1,147 ms
125,632 KB
testcase_38 AC 1,171 ms
129,548 KB
testcase_39 AC 1,135 ms
125,180 KB
testcase_40 AC 1,131 ms
126,588 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()   #python3.8からの機能
        num = f.numerator
        div = f.denominator
        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