結果
問題 | No.2966 Simple Plus Minus Problem |
ユーザー | PNJ |
提出日時 | 2024-11-16 18:04:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 347 ms / 2,567 ms |
コード長 | 5,280 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 112,260 KB |
最終ジャッジ日時 | 2024-11-16 18:04:24 |
合計ジャッジ時間 | 14,498 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,120 KB |
testcase_01 | AC | 38 ms
53,120 KB |
testcase_02 | AC | 41 ms
53,120 KB |
testcase_03 | AC | 294 ms
98,048 KB |
testcase_04 | AC | 321 ms
104,320 KB |
testcase_05 | AC | 42 ms
53,248 KB |
testcase_06 | AC | 66 ms
65,920 KB |
testcase_07 | AC | 107 ms
77,540 KB |
testcase_08 | AC | 96 ms
76,288 KB |
testcase_09 | AC | 107 ms
77,180 KB |
testcase_10 | AC | 65 ms
66,048 KB |
testcase_11 | AC | 107 ms
77,452 KB |
testcase_12 | AC | 65 ms
66,432 KB |
testcase_13 | AC | 109 ms
77,680 KB |
testcase_14 | AC | 63 ms
66,304 KB |
testcase_15 | AC | 76 ms
71,168 KB |
testcase_16 | AC | 46 ms
54,016 KB |
testcase_17 | AC | 110 ms
77,580 KB |
testcase_18 | AC | 74 ms
70,144 KB |
testcase_19 | AC | 107 ms
77,324 KB |
testcase_20 | AC | 106 ms
77,252 KB |
testcase_21 | AC | 78 ms
71,680 KB |
testcase_22 | AC | 62 ms
65,664 KB |
testcase_23 | AC | 93 ms
76,288 KB |
testcase_24 | AC | 117 ms
77,952 KB |
testcase_25 | AC | 103 ms
77,252 KB |
testcase_26 | AC | 108 ms
77,284 KB |
testcase_27 | AC | 116 ms
78,208 KB |
testcase_28 | AC | 99 ms
76,624 KB |
testcase_29 | AC | 115 ms
77,936 KB |
testcase_30 | AC | 79 ms
71,552 KB |
testcase_31 | AC | 106 ms
77,128 KB |
testcase_32 | AC | 42 ms
52,992 KB |
testcase_33 | AC | 42 ms
52,992 KB |
testcase_34 | AC | 214 ms
90,880 KB |
testcase_35 | AC | 323 ms
104,320 KB |
testcase_36 | AC | 224 ms
95,744 KB |
testcase_37 | AC | 210 ms
92,800 KB |
testcase_38 | AC | 304 ms
100,736 KB |
testcase_39 | AC | 306 ms
100,992 KB |
testcase_40 | AC | 222 ms
95,744 KB |
testcase_41 | AC | 325 ms
109,712 KB |
testcase_42 | AC | 303 ms
100,992 KB |
testcase_43 | AC | 317 ms
103,168 KB |
testcase_44 | AC | 331 ms
104,448 KB |
testcase_45 | AC | 337 ms
112,260 KB |
testcase_46 | AC | 328 ms
111,356 KB |
testcase_47 | AC | 327 ms
101,120 KB |
testcase_48 | AC | 312 ms
103,168 KB |
testcase_49 | AC | 310 ms
104,704 KB |
testcase_50 | AC | 219 ms
95,360 KB |
testcase_51 | AC | 295 ms
98,432 KB |
testcase_52 | AC | 340 ms
111,852 KB |
testcase_53 | AC | 330 ms
111,604 KB |
testcase_54 | AC | 347 ms
111,480 KB |
testcase_55 | AC | 317 ms
111,476 KB |
testcase_56 | AC | 328 ms
111,344 KB |
ソースコード
mod = 998244353 NTT_friend = [120586241,167772161,469762049,754974721,880803841,924844033,943718401,998244353,1045430273,1051721729,1053818881] NTT_dict = {} for i in range(len(NTT_friend)): NTT_dict[NTT_friend[i]] = i NTT_info = [[20,74066978],[25,17],[26,30],[24,362],[23,211],[21,44009197],[22,663003469],[23,31],[20,363],[20,330],[20,2789]] def popcount(n): c = (n&0x5555555555555555) + ((n>>1)&0x5555555555555555) c = (c&0x3333333333333333) + ((c>>2)&0x3333333333333333) c = (c&0x0f0f0f0f0f0f0f0f) + ((c>>4)&0x0f0f0f0f0f0f0f0f) c = (c&0x00ff00ff00ff00ff) + ((c>>8)&0x00ff00ff00ff00ff) c = (c&0x0000ffff0000ffff) + ((c>>16)&0x0000ffff0000ffff) c = (c&0x00000000ffffffff) + ((c>>32)&0x00000000ffffffff) return c def topbit(n): h = n.bit_length() h -= 1 return h def prepared_fft(mod = 998244353): rank2 = NTT_info[NTT_dict[mod]][0] root,iroot = [0] * 30,[0] * 30 rate2,irate2= [0] * 30,[0] * 30 rate3,irate3= [0] * 30,[0] * 30 root[rank2] = NTT_info[NTT_dict[mod]][1] iroot[rank2] = pow(root[rank2],mod - 2,mod) for i in range(rank2 - 1,-1,-1): root[i] = root[i + 1] * root[i + 1] % mod iroot[i] = iroot[i + 1] * iroot[i + 1] % mod prod,iprod = 1,1 for i in range(rank2-1): rate2[i] = root[i + 2] * prod % mod irate2[i] = iroot[i + 2] * iprod % mod prod = prod * iroot[i + 2] % mod iprod = iprod * root[i + 2] % mod prod,iprod = 1,1 for i in range(rank2-2): rate3[i] = root[i + 3] * prod % mod irate3[i] = iroot[i + 3] * iprod % mod prod = prod * iroot[i + 3] % mod iprod = iprod * root[i + 3] % mod return root,iroot,rate2,irate2,rate3,irate3 root,iroot,rate2,irate2,rate3,irate3 = prepared_fft() def ntt(a): n = len(a) h = topbit(n) assert (n == 1 << h) le = 0 while le < h: if h - le == 1: p = 1 << (h - le - 1) rot = 1 for s in range(1 << le): offset = s << (h - le) for i in range(p): l = a[i + offset] r = a[i + offset + p] * rot % mod a[i + offset] = (l + r) % mod a[i + offset + p] = (l - r) % mod rot = rot * rate2[topbit(~s & -~s)] % mod le += 1 else: p = 1 << (h - le - 2) rot,imag = 1,root[2] for s in range(1 << le): rot2 = rot * rot % mod rot3 = rot2 * rot % mod offset = s << (h - le) for i in range(p): a0 = a[i + offset] a1 = a[i + offset + p] * rot a2 = a[i + offset + p * 2] * rot2 a3 = a[i + offset + p * 3] * rot3 a1na3imag = (a1 - a3) % mod * imag a[i + offset] = (a0 + a2 + a1 + a3) % mod a[i + offset + p] = (a0 + a2 - a1 - a3) % mod a[i + offset + p * 2] = (a0 - a2 + a1na3imag) % mod a[i + offset + p * 3] = (a0 - a2 - a1na3imag) % mod rot = rot * rate3[topbit(~s & -~s)] % mod le += 2 def intt(a): n = len(a) h = topbit(n) assert (n == 1 << h) coef = pow(n,mod - 2,mod) for i in range(n): a[i] = a[i] * coef % mod le = h while le: if le == 1: p = 1 << (h - le) irot = 1 for s in range(1 << (le - 1)): offset = s << (h - le + 1) for i in range(p): l = a[i + offset] r = a[i + offset + p] a[i + offset] = (l + r) % mod a[i + offset + p] = (l - r) * irot % mod irot = irot * irate2[topbit(~s & -~s)] % mod le -= 1 else: p = 1 << (h - le) irot,iimag = 1,iroot[2] for s in range(1 << (le - 2)): irot2 = irot * irot % mod irot3 = irot2 * irot % mod offset = s << (h - le + 2) for i in range(p): a0 = a[i + offset] a1 = a[i + offset + p] a2 = a[i + offset + p * 2] a3 = a[i + offset + p * 3] a2na3iimag = (a2 - a3) * iimag % mod a[i + offset] = (a0 + a1 + a2 + a3) % mod a[i + offset + p] = (a0 - a1 + a2na3iimag) * irot % mod a[i + offset + p * 2] = (a0 + a1 - a2 - a3) * irot2 % mod a[i + offset + p * 3] = (a0 - a1 - a2na3iimag) * irot3 % mod irot *= irate3[topbit(~s & -~s)] irot %= mod le -= 2 def convolute_naive(a,b): res = [0] * (len(a) + len(b) - 1) for i in range(len(a)): for j in range(len(b)): res[i + j] = (res[i + j] + a[i] * b[j] % mod) % mod return res def convolute(a,b): s = a[:] t = b[:] n = len(s) m = len(t) if min(n,m) <= 60: return convolute_naive(s,t) le = 1 while le < n + m - 1: le *= 2 s += [0] * (le - n) t += [0] * (le - m) ntt(s) ntt(t) for i in range(le): s[i] = s[i] * t[i] % mod intt(s) s = s[:n + m - 1] return s def mod_inv(a,mod = 998244353): if mod == 1: return 0 a %= mod b,s,t = mod,1,0 while True: if a == 1: return s t -= (b // a) * s b %= a if b == 1: return t + mod s -= (a // b) * t a %= b N,K = map(int,input().split()) A = list(map(int,input().split())) f = [0 for i in range(N)] f[0] = 1 n = K // 2 for i in range(2,N,2): j = i // 2 f[i] = f[i - 2] * ((n + j - 1) * mod_inv(j) % mod) % mod f = convolute(f,A)[:N] if K % 2: for i in range(N): if i % 2: f[i] = mod - f[i] for i in range(N - 1): f[i + 1] += f[i] f[i + 1] %= mod print(*f)