結果
問題 | No.2959 Dolls' Tea Party |
ユーザー | PNJ |
提出日時 | 2024-11-08 23:37:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 8,882 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 137,588 KB |
最終ジャッジ日時 | 2024-11-08 23:38:35 |
合計ジャッジ時間 | 61,561 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
63,528 KB |
testcase_01 | AC | 52 ms
64,000 KB |
testcase_02 | AC | 51 ms
63,744 KB |
testcase_03 | AC | 52 ms
63,872 KB |
testcase_04 | AC | 60 ms
63,616 KB |
testcase_05 | AC | 51 ms
63,872 KB |
testcase_06 | AC | 281 ms
131,912 KB |
testcase_07 | AC | 449 ms
137,368 KB |
testcase_08 | AC | 308 ms
137,468 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | AC | 469 ms
137,588 KB |
testcase_15 | AC | 347 ms
137,336 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | AC | 51 ms
63,616 KB |
testcase_25 | AC | 50 ms
63,360 KB |
testcase_26 | AC | 51 ms
63,488 KB |
testcase_27 | AC | 183 ms
79,444 KB |
testcase_28 | AC | 201 ms
79,160 KB |
testcase_29 | AC | 330 ms
116,800 KB |
testcase_30 | AC | 244 ms
111,716 KB |
testcase_31 | AC | 259 ms
111,708 KB |
testcase_32 | AC | 2,097 ms
117,228 KB |
testcase_33 | AC | 2,210 ms
117,212 KB |
testcase_34 | AC | 2,192 ms
117,212 KB |
testcase_35 | AC | 2,233 ms
117,108 KB |
testcase_36 | AC | 2,104 ms
122,324 KB |
ソースコード
def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i < n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 if i * i == n: lower_divisors.append(i) return lower_divisors + upper_divisors[::-1] def gcd(a, b): while a != 0: b %= a if b == 0: return a a %= b return b mod = 998244353 n = 10000 inv = [1 for j in range(n + 1)] for a in range(2,n + 1): # ax + py = 1 <=> rx + p(-x-qy) = -q => x = -(inv[r]) * (p//a) (r = p % a) res = (mod - inv[mod % a]) * (mod // a) inv[a] = res % mod fact = [1 for i in range(n + 1)] for i in range(1,n + 1): fact[i] = fact[i - 1] * i % mod fact_inv = [1 for i in range(n + 1)] fact_inv[-1] = pow(fact[-1],mod - 2,mod) for i in range(n,0,-1): fact_inv[i - 1] = fact_inv[i] * i % mod 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 = inv[n] 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) <= 30: return convolute_naive(a,b) 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 fps_inv(f,deg = -1): if deg == -1: deg = len(f) res = [0] * deg res[0] = 1 d = 1 while d < deg: a = [0] * (d << 1) tmp = min(len(f),d << 1) a[:tmp] = f[:tmp] b = [0] * (d << 1) b[:d] = res[:d] ntt(a) ntt(b) for i in range(d << 1): a[i] = a[i] * b[i] % mod intt(a) a[:d] = [0] * d ntt(a) for i in range(d << 1): a[i] = a[i] * b[i] % mod intt(a) for j in range(d,min(d << 1,deg)): if a[j]: res[j] = mod - a[j] else: res[j] = 0 d <<= 1 return res def fps_div(f,g): n,m = len(f),len(g) if n < m: return [],f rev_f = f[:] rev_f = rev_f[::-1] rev_g = g[:] rev_g = rev_g[::-1] rev_q = convolute(rev_f,fps_inv(rev_g,n-m+1))[:n-m+1] q = rev_q[:] q = q[::-1] p = convolute(g,q) r = f[:] for i in range(min(len(p),len(r))): r[i] -= p[i] r[i] %= mod while len(r): if r[-1] != 0: break r.pop() return q,r def fps_add(f,g): n = max(len(f),len(g)) res = [0] * n for i in range(len(f)): res[i] = f[i] for i in range(len(g)): res[i] = (res[i] + g[i]) % mod return res def fps_diff(f): if len(f) <= 1: return [0] res = [] for i in range(1,len(f)): res.append(i * f[i] % mod) return res def fps_integrate(f): n = len(f) res = [0] * (n + 1) for i in range(n): res[i + 1] = inv[i + 1] * f[i] % mod return res def fps_log(f,deg = -1): assert (f[0] == 1) if deg == -1: deg = len(f) res = convolute(fps_diff(f),fps_inv(f,deg))[:deg - 1] res = fps_integrate(res) return res def fps_exp(f,deg = -1): if deg == -1: deg = len(f) res = [1,0] if len(f) > 1: res[1] = f[1] g = [1] p = [] q = [1,1] m = 2 while m < deg: y = res + [0]*m ntt(y) p = q[:] z = [y[i] * p[i] for i in range(len(p))] intt(z) z[:m >> 1] = [0] * (m >> 1) ntt(z) for i in range(len(p)): z[i] = z[i] * (-p[i]) % mod intt(z) g[m >> 1:] = z[m >> 1:] q = g + [0] * m ntt(q) tmp = min(len(f),m) x = f[:tmp] + [0] * (m - tmp) x = fps_diff(x) x.append(0) ntt(x) for i in range(len(x)): x[i] = x[i] * y[i] % mod intt(x) for i in range(len(res)): if i == 0: continue x[i-1] -= res[i] * i % mod x += [0] * m for i in range(m-1): x[m+i],x[i] = x[i],0 ntt(x) for i in range(len(q)): x[i] = x[i] * q[i] % mod intt(x) x.pop() x = fps_integrate(x) x[:m] = [0] * m for i in range(m,min(len(f),m << 1)): x[i] += f[i] ntt(x) for i in range(len(y)): x[i] = x[i] * y[i] % mod intt(x) res[m:] = x[m:] m <<= 1 return res[:deg] N,K = map(int,input().split()) A = list(map(int,input().split())) D = make_divisors(K) M = len(D) dic = {} for i in range(M): dic[D[i]] = i C = [] for d in D: n = K // d Q = [0 for i in range(n + 1)] for a in A: Q[min(n,a // d)] += 1 f = [0 for j in range(n + 1)] f[1] = sum(Q) - Q[0] g = [1] for i in range(1,n): g.append(fact_inv[i]) if Q[i] == 0: continue gg = fps_log(g,n + 1) for j in range(i + 1,n + 1): f[j] = (f[j] + gg[j] * Q[i] % mod) % mod f = fps_exp(f) C.append(f[n] * fact[n] % mod) res = 0 for k in range(1,K + 1): g = gcd(k,K) d = K // g res += C[dic[d]] res %= mod res = res * inv[K] % mod print(res)