結果
問題 | No.1100 Boxes |
ユーザー | convexineq |
提出日時 | 2023-07-10 16:57:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 273 ms / 2,000 ms |
コード長 | 2,499 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,788 KB |
実行使用メモリ | 103,172 KB |
最終ジャッジ日時 | 2024-09-12 23:41:16 |
合計ジャッジ時間 | 6,665 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
75,184 KB |
testcase_01 | AC | 62 ms
74,932 KB |
testcase_02 | AC | 63 ms
75,756 KB |
testcase_03 | AC | 69 ms
78,992 KB |
testcase_04 | AC | 63 ms
75,512 KB |
testcase_05 | AC | 63 ms
75,172 KB |
testcase_06 | AC | 63 ms
75,124 KB |
testcase_07 | AC | 66 ms
75,088 KB |
testcase_08 | AC | 62 ms
75,136 KB |
testcase_09 | AC | 63 ms
75,160 KB |
testcase_10 | AC | 62 ms
74,984 KB |
testcase_11 | AC | 63 ms
76,344 KB |
testcase_12 | AC | 64 ms
76,728 KB |
testcase_13 | AC | 63 ms
74,860 KB |
testcase_14 | AC | 68 ms
77,480 KB |
testcase_15 | AC | 68 ms
77,752 KB |
testcase_16 | AC | 69 ms
77,048 KB |
testcase_17 | AC | 79 ms
84,052 KB |
testcase_18 | AC | 78 ms
84,408 KB |
testcase_19 | AC | 88 ms
89,552 KB |
testcase_20 | AC | 105 ms
92,812 KB |
testcase_21 | AC | 158 ms
96,964 KB |
testcase_22 | AC | 240 ms
102,220 KB |
testcase_23 | AC | 159 ms
96,836 KB |
testcase_24 | AC | 169 ms
97,496 KB |
testcase_25 | AC | 173 ms
97,808 KB |
testcase_26 | AC | 253 ms
103,172 KB |
testcase_27 | AC | 249 ms
101,928 KB |
testcase_28 | AC | 130 ms
94,616 KB |
testcase_29 | AC | 261 ms
102,508 KB |
testcase_30 | AC | 251 ms
101,852 KB |
testcase_31 | AC | 137 ms
94,708 KB |
testcase_32 | AC | 187 ms
97,488 KB |
testcase_33 | AC | 273 ms
102,932 KB |
testcase_34 | AC | 267 ms
103,100 KB |
testcase_35 | AC | 66 ms
75,964 KB |
testcase_36 | AC | 215 ms
102,716 KB |
testcase_37 | AC | 64 ms
75,520 KB |
testcase_38 | AC | 161 ms
97,328 KB |
testcase_39 | AC | 245 ms
102,956 KB |
ソースコード
SIZE=10**6+1 MOD = 998244353 ROOT = 3 roots = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根 iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元 def untt(a,n): for i in range(n): m = 1<<(n-i-1) for s in range(1<<i): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD w_N = w_N*roots[n-i]%MOD def iuntt(a,n): for i in range(n): m = 1<<i for s in range(1<<(n-i-1)): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD w_N = w_N*iroots[i+1]%MOD inv = pow((MOD+1)//2,n,MOD) for i in range(1<<n): a[i] = a[i]*inv%MOD def convolution(a,b): la = len(a) lb = len(b) if min(la, lb) <= 50: if la < lb: la,lb = lb,la a,b = b,a res = [0]*(la+lb-1) for i in range(la): for j in range(lb): res[i+j] += a[i]*b[j] res[i+j] %= MOD return res deg = la+lb-2 n = deg.bit_length() N = 1<<n a += [0]*(N-len(a)) b += [0]*(N-len(b)) untt(a,n) untt(b,n) for i in range(N): a[i] = a[i]*b[i]%MOD iuntt(a,n) return a[:deg+1] #inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD #inv[i] = finv[i]*fac[i-1]%MOD def polynomial_Taylor_shift(f,c): N = len(f) f = f[:] g = [1]*N cc = c for i in range(1,N): f[i] = f[i]*fac[i]%MOD g[N-i-1] = cc*finv[i]%MOD cc = cc*c%MOD h = convolution(f,g)[N-1:] for i in range(N): h[i] = h[i]*finv[i]%MOD return h def choose(n,r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD else: return 0 ############################################################### import sys readline = sys.stdin.readline n,k = map(int,readline().split()) g = [pow(i,n,MOD)*choose(k,i)%MOD for i in range(k+1)] g = g[::-1] f = polynomial_Taylor_shift(g,-1) f = f[::-1] ans = sum(f[(k+1)%2::2])%MOD print(ans)