結果

問題 No.1856 Mex Sum 2
ユーザー tamatotamato
提出日時 2022-02-26 11:13:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,911 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 140,484 KB
最終ジャッジ日時 2023-09-17 10:31:09
合計ジャッジ時間 19,090 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
80,144 KB
testcase_01 AC 78 ms
75,816 KB
testcase_02 AC 121 ms
77,144 KB
testcase_03 AC 79 ms
75,756 KB
testcase_04 AC 96 ms
76,868 KB
testcase_05 AC 83 ms
76,408 KB
testcase_06 AC 83 ms
76,456 KB
testcase_07 AC 88 ms
76,312 KB
testcase_08 AC 79 ms
75,892 KB
testcase_09 AC 83 ms
76,236 KB
testcase_10 AC 81 ms
76,532 KB
testcase_11 AC 83 ms
76,236 KB
testcase_12 AC 81 ms
75,656 KB
testcase_13 AC 79 ms
75,884 KB
testcase_14 AC 79 ms
75,756 KB
testcase_15 AC 79 ms
75,916 KB
testcase_16 AC 85 ms
76,220 KB
testcase_17 AC 118 ms
77,396 KB
testcase_18 AC 112 ms
77,200 KB
testcase_19 AC 83 ms
76,296 KB
testcase_20 AC 85 ms
76,204 KB
testcase_21 AC 81 ms
75,960 KB
testcase_22 AC 118 ms
76,880 KB
testcase_23 AC 80 ms
75,908 KB
testcase_24 AC 89 ms
76,572 KB
testcase_25 AC 114 ms
77,392 KB
testcase_26 AC 80 ms
75,736 KB
testcase_27 AC 77 ms
75,640 KB
testcase_28 AC 80 ms
75,984 KB
testcase_29 AC 1,141 ms
90,500 KB
testcase_30 AC 643 ms
84,196 KB
testcase_31 AC 1,100 ms
89,936 KB
testcase_32 AC 1,630 ms
97,360 KB
testcase_33 AC 1,810 ms
99,648 KB
testcase_34 AC 1,102 ms
89,496 KB
testcase_35 AC 659 ms
84,236 KB
testcase_36 AC 346 ms
80,752 KB
testcase_37 AC 1,068 ms
89,540 KB
testcase_38 AC 278 ms
79,456 KB
testcase_39 AC 101 ms
77,052 KB
testcase_40 AC 115 ms
77,360 KB
testcase_41 AC 116 ms
77,352 KB
testcase_42 TLE -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
W = (
1, 998244352, 911660635, 372528824, 929031873, 452798380, 922799308, 781712469, 476477967, 166035806, 258648936,
584193783, 63912897, 350007156, 666702199, 968855178, 629671588, 24514907, 996173970, 363395222, 565042129,
733596141, 267099868, 15311432)
IW = (1, 998244352, 86583718, 509520358, 337190230, 87557064, 609441965, 135236158, 304459705, 685443576, 381598368,
      335559352, 129292727, 358024708, 814576206, 708402881, 283043518, 3707709, 121392023, 704923114, 950391366,
      428961804, 382752275, 469870224)


def main():
    import sys
    input = sys.stdin.readline

    # A: 係数を並べたベクトル,len(A) = 2^n
    def fft(A):
        N = len(A)
        n = N.bit_length() - 1
        N2 = N // 2
        A_new = [0] * N
        for lv in range(n):
            L = 1 << (n - lv - 1)
            w = W[lv + 1]
            ww = 1
            for j in range(1 << lv):
                for i in range(L):
                    f0_val = A[i + j * L * 2]
                    f1_val = A[i + j * L * 2 + L]
                    tmp = (ww * f1_val) % mod
                    A_new[i + j * L] = (f0_val + tmp) % mod
                    A_new[i + j * L + N2] = (f0_val - tmp) % mod
                ww = (ww * w) % mod
            A, A_new = A_new, A
        return A

    # A: 係数を並べたベクトル,len(A) = 2^n
    def ifft(A):
        N = len(A)
        n = N.bit_length() - 1
        N2 = N // 2
        A_new = [0] * N
        for lv in range(n):
            L = 1 << (n - lv - 1)
            w = IW[lv + 1]
            ww = 1
            for j in range(1 << lv):
                for i in range(L):
                    f0_val = A[i + j * L * 2]
                    f1_val = A[i + j * L * 2 + L]
                    tmp = (ww * f1_val) % mod
                    A_new[i + j * L] = (f0_val + tmp) % mod
                    A_new[i + j * L + N2] = (f0_val - tmp) % mod
                ww = (ww * w) % mod
            A, A_new = A_new, A
        return A

    def convolution(A0, B0, limit):
        if len(A0) <= 60 or len(B0) <= 60:
            return convolution_naive(A0, B0, limit)
        N = len(A0) + len(B0) - 1
        N0 = 1 << ((N - 1).bit_length())
        A = A0 + [0] * (N0 - len(A0))
        B = B0 + [0] * (N0 - len(B0))
        AA = fft(A)
        BB = fft(B)
        CC = [(aa * bb) % mod for aa, bb in zip(AA, BB)]
        C = ifft(CC)
        invN0 = pow(N0, mod - 2, mod)
        C = [(c * invN0) % mod for c in C]
        return C[:limit]

    def convolution_naive(A0, B0, limit):
        NA = len(A0)
        NB = len(B0)
        C = [0] * (NA + NB - 1)
        for i in range(NA):
            for j in range(NB):
                C[i + j] = (C[i + j] + (A0[i] * B0[j]) % mod) % mod
        return C[:limit]

    # comb init
    nmax = 2 * 10 ** 3 + 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

    N, M = map(int, input().split())
    vec = []
    for i in range(N+1):
        vec.append(((pow(2, i, mod) - 1) * finv[i])%mod)
    dp = [vec[:]]
    for i in range(1, min(N, M + 1)):
        dp.append(convolution(vec, dp[-1], N+1))

    ans = 0
    for i in range(min(N, M + 1)):
        for j in range(N + 1):
            if i == M:
                if j == N:
                    ans = (ans + dp[i][j])%mod
            else:
                ans = (ans + ((dp[i][j] * pow(M - i, N - j, mod))%mod * (finv[N - j] * pow(2, N - j, mod))%mod)%mod)%mod
    print((ans * fac[N])%mod)


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