結果

問題 No.1856 Mex Sum 2
ユーザー MitarushiMitarushi
提出日時 2022-02-24 23:31:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,352 ms / 3,000 ms
コード長 2,041 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 77,500 KB
最終ジャッジ日時 2024-07-02 14:16:10
合計ジャッジ時間 40,264 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 41 ms
52,480 KB
testcase_02 AC 85 ms
76,032 KB
testcase_03 AC 41 ms
52,352 KB
testcase_04 AC 62 ms
64,896 KB
testcase_05 AC 63 ms
65,920 KB
testcase_06 AC 63 ms
65,152 KB
testcase_07 AC 78 ms
71,424 KB
testcase_08 AC 42 ms
52,096 KB
testcase_09 AC 60 ms
63,488 KB
testcase_10 AC 62 ms
64,768 KB
testcase_11 AC 63 ms
64,896 KB
testcase_12 AC 49 ms
59,392 KB
testcase_13 AC 41 ms
51,968 KB
testcase_14 AC 41 ms
52,224 KB
testcase_15 AC 42 ms
52,224 KB
testcase_16 AC 63 ms
65,024 KB
testcase_17 AC 85 ms
75,904 KB
testcase_18 AC 80 ms
74,112 KB
testcase_19 AC 65 ms
65,792 KB
testcase_20 AC 65 ms
65,408 KB
testcase_21 AC 43 ms
53,248 KB
testcase_22 AC 86 ms
76,032 KB
testcase_23 AC 44 ms
52,864 KB
testcase_24 AC 76 ms
70,784 KB
testcase_25 AC 85 ms
76,160 KB
testcase_26 AC 41 ms
52,480 KB
testcase_27 AC 41 ms
51,968 KB
testcase_28 AC 44 ms
53,248 KB
testcase_29 AC 400 ms
76,856 KB
testcase_30 AC 264 ms
76,976 KB
testcase_31 AC 383 ms
77,104 KB
testcase_32 AC 540 ms
76,856 KB
testcase_33 AC 560 ms
77,108 KB
testcase_34 AC 388 ms
76,724 KB
testcase_35 AC 282 ms
76,720 KB
testcase_36 AC 180 ms
77,236 KB
testcase_37 AC 382 ms
76,856 KB
testcase_38 AC 158 ms
76,984 KB
testcase_39 AC 110 ms
76,848 KB
testcase_40 AC 115 ms
76,472 KB
testcase_41 AC 113 ms
76,600 KB
testcase_42 AC 1,290 ms
76,860 KB
testcase_43 AC 1,161 ms
76,972 KB
testcase_44 AC 1,214 ms
76,892 KB
testcase_45 AC 1,275 ms
76,852 KB
testcase_46 AC 1,168 ms
76,852 KB
testcase_47 AC 1,228 ms
76,852 KB
testcase_48 AC 1,311 ms
76,980 KB
testcase_49 AC 1,293 ms
77,116 KB
testcase_50 AC 1,070 ms
77,484 KB
testcase_51 AC 1,352 ms
76,984 KB
testcase_52 AC 1,312 ms
76,984 KB
testcase_53 AC 1,325 ms
76,992 KB
testcase_54 AC 1,322 ms
77,496 KB
testcase_55 AC 1,327 ms
77,116 KB
testcase_56 AC 1,323 ms
76,984 KB
testcase_57 AC 1,319 ms
77,496 KB
testcase_58 AC 1,324 ms
76,856 KB
testcase_59 AC 1,321 ms
76,860 KB
testcase_60 AC 1,330 ms
77,244 KB
testcase_61 AC 1,322 ms
77,100 KB
testcase_62 AC 1,330 ms
77,120 KB
testcase_63 AC 1,320 ms
77,500 KB
testcase_64 AC 1,321 ms
77,244 KB
testcase_65 AC 1,322 ms
77,368 KB
testcase_66 AC 1,325 ms
76,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def fft_inplace(a, w):
    n = len(a)
    m = n
    t = 1
    while m >= 2:
        mh = m >> 1
        for i in range(0, n, m):
            for s in range(mh):
                j, k = i+s, i+mh+s
                a[j], u = a[j]+a[k], a[j]-a[k]
                a[k] = u * w[s*t] % 998244353
        m = mh
        t *= 2


def ifft_inplace(a, w):
    n = len(a)
    m = 2
    t = -(n >> 1)
    while m <= n:
        mh = m >> 1
        for i in range(0, n, m):
            for s in range(mh):
                j, k = i+s, i+mh+s
                u = a[k] * w[s*t] % 998244353
                a[j], a[k] = a[j]+u, a[j]-u
        m <<= 1
        t //= 2
    n_inv = pow(n, 998244353-2, 998244353)
    for i in range(n):
        a[i] = a[i] * n_inv % 998244353


n, m = map(int, input().split())
assert 1 <= n <= 2000
assert 1 <= m <= 10 ** 9
fixed_n = 1 << ((n+1)*2).bit_length()

w_root = pow(3, (998244353-1)//fixed_n, 998244353)
w = [1] * fixed_n
for i in range(1, fixed_n):
    w[i] = w[i-1] * w_root % 998244353

frac = [1] * (n + 1)
for i in range(1, n+1):
    frac[i] = frac[i-1] * i % 998244353
frac_inv = [0] * (n+1)
frac_inv[n] = pow(frac[n], 998244353-2, 998244353)
for i in range(1, n+1)[::-1]:
    frac_inv[i-1] = frac_inv[i] * i % 998244353

dp1 = [0] * fixed_n
dp1[0] = 1

t = [0] * fixed_n
for i in range(n+1):
    t[i] = (pow(2, i, 998244353)-1) * pow(pow(2, i, 998244353) * frac[i], 998244353-2, 998244353) % 998244353

fft_inplace(t, w)

ans_sub = [0] * (n+1)
for k in range(min(n, m+1)):
    fft_inplace(dp1, w)
    for i, j in enumerate(t):
        dp1[i] = dp1[i] * j % 998244353
    ifft_inplace(dp1, w)

    pow_tmp = 1
    for i in range(k+1, n+1)[::-1]:
        ans_sub[i] += dp1[i] * pow_tmp % 998244353
        pow_tmp = pow_tmp * (m - k) % 998244353
    for i in range(n+1, fixed_n):
        dp1[i] = 0

ans = sum(ans_sub[i] % 998244353 * frac_inv[n-i] for i in range(n+1)) % 998244353
ans = ans * pow(2, n, 998244353) * frac[n] % 998244353
print(ans)

try:
    x = input()
    assert x == ""
except EOFError:
    pass
0