結果
問題 | No.1100 Boxes |
ユーザー | shotoyoo |
提出日時 | 2021-06-22 00:56:58 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,164 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 86,984 KB |
実行使用メモリ | 81,044 KB |
最終ジャッジ日時 | 2023-09-05 02:04:42 |
合計ジャッジ時間 | 9,836 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
ソースコード
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)