結果

問題 No.1554 array_and_me
ユーザー tamatotamato
提出日時 2021-06-18 22:42:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,363 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 100,760 KB
最終ジャッジ日時 2023-09-04 23:50:59
合計ジャッジ時間 8,836 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
78,456 KB
testcase_01 AC 128 ms
79,940 KB
testcase_02 AC 122 ms
79,892 KB
testcase_03 AC 123 ms
80,204 KB
testcase_04 AC 124 ms
80,232 KB
testcase_05 AC 121 ms
80,108 KB
testcase_06 AC 213 ms
100,360 KB
testcase_07 AC 212 ms
100,352 KB
testcase_08 AC 213 ms
100,528 KB
testcase_09 AC 210 ms
100,552 KB
testcase_10 AC 210 ms
100,432 KB
testcase_11 AC 205 ms
100,420 KB
testcase_12 AC 206 ms
100,520 KB
testcase_13 AC 206 ms
100,540 KB
testcase_14 AC 205 ms
100,760 KB
testcase_15 AC 204 ms
100,352 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 AC 178 ms
82,316 KB
testcase_27 AC 180 ms
82,420 KB
testcase_28 AC 179 ms
82,492 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 179 ms
82,720 KB
testcase_32 WA -
testcase_33 AC 180 ms
82,340 KB
testcase_34 AC 180 ms
82,692 KB
testcase_35 WA -
testcase_36 AC 154 ms
82,784 KB
testcase_37 AC 153 ms
82,616 KB
testcase_38 AC 153 ms
82,352 KB
testcase_39 AC 156 ms
82,360 KB
testcase_40 AC 154 ms
82,704 KB
testcase_41 AC 125 ms
80,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    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
        for i in range(N):
            B[i] = K * A[i] // S
        C = []
        for i in range(N):
            b = B[i]
            C.append((i, A[i] * (K - b) / (b + 1)))
        C.sort(key=lambda x: x[1], reverse=True)
        SB = sum(B)
        for i in range(K - SB):
            B[C[i][0]] += 1
        ans = 1
        S_inv = pow(S, mod-2, mod)
        T = K
        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