結果

問題 No.1856 Mex Sum 2
ユーザー MitarushiMitarushi
提出日時 2021-04-17 17:41:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,462 ms / 3,000 ms
コード長 1,801 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 77,680 KB
最終ジャッジ日時 2024-07-04 04:43:12
合計ジャッジ時間 42,897 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,628 KB
testcase_01 AC 40 ms
54,540 KB
testcase_02 AC 79 ms
76,492 KB
testcase_03 AC 38 ms
52,944 KB
testcase_04 AC 61 ms
67,120 KB
testcase_05 AC 59 ms
67,700 KB
testcase_06 AC 58 ms
66,116 KB
testcase_07 AC 72 ms
71,060 KB
testcase_08 AC 39 ms
53,932 KB
testcase_09 AC 54 ms
65,084 KB
testcase_10 AC 57 ms
65,384 KB
testcase_11 AC 58 ms
66,324 KB
testcase_12 AC 45 ms
60,620 KB
testcase_13 AC 38 ms
52,452 KB
testcase_14 AC 39 ms
52,456 KB
testcase_15 AC 40 ms
52,276 KB
testcase_16 AC 58 ms
65,804 KB
testcase_17 AC 78 ms
76,264 KB
testcase_18 AC 77 ms
76,556 KB
testcase_19 AC 58 ms
66,660 KB
testcase_20 AC 56 ms
66,412 KB
testcase_21 AC 40 ms
54,736 KB
testcase_22 AC 78 ms
76,652 KB
testcase_23 AC 41 ms
53,540 KB
testcase_24 AC 67 ms
72,812 KB
testcase_25 AC 79 ms
76,456 KB
testcase_26 AC 39 ms
53,836 KB
testcase_27 AC 40 ms
52,392 KB
testcase_28 AC 41 ms
54,140 KB
testcase_29 AC 423 ms
76,924 KB
testcase_30 AC 269 ms
76,920 KB
testcase_31 AC 402 ms
77,236 KB
testcase_32 AC 573 ms
77,408 KB
testcase_33 AC 593 ms
77,680 KB
testcase_34 AC 404 ms
77,324 KB
testcase_35 AC 287 ms
77,064 KB
testcase_36 AC 183 ms
76,800 KB
testcase_37 AC 391 ms
76,984 KB
testcase_38 AC 156 ms
76,804 KB
testcase_39 AC 100 ms
76,528 KB
testcase_40 AC 105 ms
76,804 KB
testcase_41 AC 105 ms
76,664 KB
testcase_42 AC 1,417 ms
77,352 KB
testcase_43 AC 1,272 ms
77,160 KB
testcase_44 AC 1,330 ms
77,068 KB
testcase_45 AC 1,397 ms
77,288 KB
testcase_46 AC 1,282 ms
77,180 KB
testcase_47 AC 1,341 ms
77,424 KB
testcase_48 AC 1,426 ms
77,044 KB
testcase_49 AC 1,424 ms
77,188 KB
testcase_50 AC 1,163 ms
77,164 KB
testcase_51 AC 1,450 ms
77,176 KB
testcase_52 AC 1,452 ms
77,572 KB
testcase_53 AC 1,459 ms
77,192 KB
testcase_54 AC 1,459 ms
77,044 KB
testcase_55 AC 1,456 ms
77,060 KB
testcase_56 AC 1,455 ms
77,580 KB
testcase_57 AC 1,455 ms
77,052 KB
testcase_58 AC 1,462 ms
77,316 KB
testcase_59 AC 1,451 ms
77,172 KB
testcase_60 AC 1,457 ms
77,040 KB
testcase_61 AC 1,453 ms
77,064 KB
testcase_62 AC 1,455 ms
77,064 KB
testcase_63 AC 1,456 ms
77,428 KB
testcase_64 AC 1,459 ms
76,856 KB
testcase_65 AC 1,456 ms
77,052 KB
testcase_66 AC 1,456 ms
77,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


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], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k])*w[s*t] % mod
        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
                a[k] *= w[s*t]
                a[j], a[k] = (a[j]+a[k]) % mod, (a[j]-a[k]) % mod
        m <<= 1
        t //= 2
    n_inv = pow(n, mod-2, mod)
    for i in range(n):
        a[i] = a[i] * n_inv % mod


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

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

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

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

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

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 % mod
    ifft_inplace(dp1, w)

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

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