結果

問題 No.1554 array_and_me
ユーザー 👑 tamatotamato
提出日時 2021-06-18 23:15:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 87,536 KB
実行使用メモリ 95,000 KB
最終ジャッジ日時 2023-09-05 00:11:08
合計ジャッジ時間 18,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
78,672 KB
testcase_01 AC 326 ms
83,584 KB
testcase_02 AC 315 ms
83,460 KB
testcase_03 AC 323 ms
83,604 KB
testcase_04 AC 306 ms
83,432 KB
testcase_05 AC 334 ms
84,056 KB
testcase_06 AC 555 ms
95,000 KB
testcase_07 AC 554 ms
94,572 KB
testcase_08 AC 529 ms
93,796 KB
testcase_09 AC 559 ms
94,008 KB
testcase_10 AC 553 ms
93,620 KB
testcase_11 AC 149 ms
93,504 KB
testcase_12 AC 151 ms
93,596 KB
testcase_13 AC 154 ms
93,700 KB
testcase_14 AC 156 ms
93,384 KB
testcase_15 AC 151 ms
93,692 KB
testcase_16 AC 181 ms
81,580 KB
testcase_17 AC 180 ms
81,000 KB
testcase_18 AC 186 ms
81,132 KB
testcase_19 AC 183 ms
80,624 KB
testcase_20 AC 177 ms
80,808 KB
testcase_21 AC 531 ms
85,692 KB
testcase_22 AC 519 ms
87,336 KB
testcase_23 AC 521 ms
86,348 KB
testcase_24 AC 516 ms
85,440 KB
testcase_25 AC 523 ms
86,576 KB
testcase_26 AC 522 ms
91,944 KB
testcase_27 AC 526 ms
90,952 KB
testcase_28 AC 544 ms
92,120 KB
testcase_29 AC 512 ms
91,868 KB
testcase_30 AC 518 ms
91,108 KB
testcase_31 AC 533 ms
92,936 KB
testcase_32 AC 529 ms
93,572 KB
testcase_33 AC 556 ms
92,072 KB
testcase_34 AC 523 ms
92,676 KB
testcase_35 AC 531 ms
93,616 KB
testcase_36 AC 323 ms
89,256 KB
testcase_37 AC 319 ms
90,108 KB
testcase_38 AC 316 ms
88,704 KB
testcase_39 AC 321 ms
89,332 KB
testcase_40 AC 321 ms
89,280 KB
testcase_41 AC 314 ms
82,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    from heapq import heappop, heappush
    input = sys.stdin.readline

    # comb init
    nmax = 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    for _ in range(int(input())):
        N, K = map(int, input().split())
        A = list(map(int, input().split()))

        S = sum(A)
        B = [0] * N
        pq = []
        for i in range(N):
            heappush(pq, (-A[i], i))
        for _ in range(K):
            v, i = heappop(pq)
            B[i] += 1
            heappush(pq, (-A[i] * (1 / (B[i] + 1)), i))
        S_inv = pow(S, mod-2, mod)
        T = K
        ans = 1
        for i in range(N):
            ans = (ans * pow((A[i] * S_inv)%mod, B[i], mod))%mod
            ans = (ans * comb(T, B[i]))%mod
            T -= B[i]
        print(ans)
        assert T == 0


if __name__ == '__main__':
    main()
0