結果

問題 No.1100 Boxes
ユーザー shotoyooshotoyoo
提出日時 2021-06-22 00:57:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 859 ms / 2,000 ms
コード長 2,164 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 72,188 KB
最終ジャッジ日時 2023-09-05 02:05:01
合計ジャッジ時間 17,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
29,928 KB
testcase_01 AC 138 ms
30,108 KB
testcase_02 AC 138 ms
30,036 KB
testcase_03 AC 139 ms
30,020 KB
testcase_04 AC 140 ms
30,004 KB
testcase_05 AC 139 ms
30,064 KB
testcase_06 AC 137 ms
29,916 KB
testcase_07 AC 139 ms
30,068 KB
testcase_08 AC 140 ms
29,924 KB
testcase_09 AC 141 ms
30,056 KB
testcase_10 AC 138 ms
30,064 KB
testcase_11 AC 137 ms
30,036 KB
testcase_12 AC 136 ms
30,096 KB
testcase_13 AC 134 ms
29,992 KB
testcase_14 AC 136 ms
30,052 KB
testcase_15 AC 137 ms
29,952 KB
testcase_16 AC 137 ms
29,924 KB
testcase_17 AC 143 ms
30,308 KB
testcase_18 AC 138 ms
30,192 KB
testcase_19 AC 150 ms
31,372 KB
testcase_20 AC 270 ms
34,904 KB
testcase_21 AC 393 ms
48,236 KB
testcase_22 AC 694 ms
68,644 KB
testcase_23 AC 390 ms
48,388 KB
testcase_24 AC 453 ms
50,164 KB
testcase_25 AC 477 ms
51,828 KB
testcase_26 AC 782 ms
70,452 KB
testcase_27 AC 707 ms
66,468 KB
testcase_28 AC 286 ms
39,824 KB
testcase_29 AC 795 ms
68,252 KB
testcase_30 AC 707 ms
65,264 KB
testcase_31 AC 347 ms
42,496 KB
testcase_32 AC 573 ms
53,416 KB
testcase_33 AC 859 ms
71,172 KB
testcase_34 AC 840 ms
72,188 KB
testcase_35 AC 137 ms
30,112 KB
testcase_36 AC 632 ms
71,712 KB
testcase_37 AC 136 ms
30,008 KB
testcase_38 AC 418 ms
49,808 KB
testcase_39 AC 769 ms
70,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,k = list(map(int, input().split()))
M = 998244353
### 素数の逆元とCombination

N = k+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M
# FFT
import numpy as np
TYPE = np.int64
M = 998244353
def fft(a,b):
    l = len(a) + len(b) - 1
    l = 1<<((l-1).bit_length())
    c = np.fft.irfft((np.fft.rfft(a,l))*(np.fft.rfft(b,l)),l)
    c = np.rint(c).astype(TYPE)
    return c
def fft_large(a,b):
    d = 30000
    a1, a2 = np.divmod(a,d)
    b1, b2 = np.divmod(b,d)
    aa = fft(a1,b1) % M
    bb = fft(a2,b2) % M
    cc = (fft(a1+a2, b1+b2) - (aa+bb)) % M
    h = (((aa*d)%M)*d  + cc*d + bb) % M
    return h
def fft_large(a,b):
    """精度が足りないときはこちら
    """
    d = 1<<10
    a1, a2 = np.divmod(a,d*d)
    a2, a3 = np.divmod(a2,d)
    b1, b2 = np.divmod(b,d*d)
    b2, b3 = np.divmod(b2,d)
    aa = fft(a1,b1) % M
    bb = fft(a2,b2) % M
    cc = fft(a3,b3) % M
    dd = (fft(a1+a2, b1+b2) - (aa+bb)) % M
    ee = (fft(a2+a3, b2+b3) - (bb+cc)) % M
    ff = (fft(a1+a3, b1+b3) - (aa+cc)) % M
    h = (((aa*d*d)%M)*d*d + ((dd*d*d)%M)*d + (bb+ff)*d*d + ee*d + cc) % M
    return h
ans = 0
gg = fft_large(g2,g2)
inv2 = pow(2, M-2, M)
gg *= inv2
gg %= M
gg = gg.tolist()
s = 1
for i in range(1,k):
    ans += s * pow(k-i, n, M) * (perm(k,i) * gg[i] % M) % M
    ans %= M
    s *= -1
print(ans)
0