結果
問題 | No.2770 Coupon Optimization |
ユーザー | PNJ |
提出日時 | 2024-07-21 06:23:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 935 ms / 3,000 ms |
コード長 | 5,311 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 148,280 KB |
最終ジャッジ日時 | 2024-07-21 06:23:28 |
合計ジャッジ時間 | 15,794 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,504 KB |
testcase_01 | AC | 43 ms
53,760 KB |
testcase_02 | AC | 43 ms
52,864 KB |
testcase_03 | AC | 831 ms
129,036 KB |
testcase_04 | AC | 864 ms
144,408 KB |
testcase_05 | AC | 375 ms
112,640 KB |
testcase_06 | AC | 877 ms
144,956 KB |
testcase_07 | AC | 855 ms
124,492 KB |
testcase_08 | AC | 900 ms
147,844 KB |
testcase_09 | AC | 439 ms
105,856 KB |
testcase_10 | AC | 475 ms
97,152 KB |
testcase_11 | AC | 471 ms
99,968 KB |
testcase_12 | AC | 798 ms
122,184 KB |
testcase_13 | AC | 514 ms
99,584 KB |
testcase_14 | AC | 935 ms
147,084 KB |
testcase_15 | AC | 908 ms
148,280 KB |
testcase_16 | AC | 930 ms
147,328 KB |
testcase_17 | AC | 931 ms
147,716 KB |
ソースコード
mod = 998244353 MOD = [120586241,167772161,469762049,754974721,880803841,943718401,998244353 ,1045430273,1051721729,1053818881] NTT_dict = {} for i in range(10): NTT_dict[MOD[i]] = i NTT_info = [[20,74066978],[25,17],[26,30],[24,362],[23,211],[22,663003469],[23,31] ,[20,363],[20,330],[20,2789]] 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 = n.bit_length() - 1 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(a,b): n = len(a) m = len(b) aa = a[:] bb = b[:] sz = 1 << (n + m - 2).bit_length() aa += [0] * (sz - n) bb += [0] * (sz - m) ntt(aa) ntt(bb) for i in range(sz): aa[i] = aa[i] * bb[i] % mod intt(aa) aa = aa[:(n + m - 1)] return aa N,M = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) for i in range(N): A[i] //= 100 for i in range(M): B[i] = 100 - B[i] while len(B) < N: B.append(100) A.sort() B.sort() C = convolute(A,B) mod1 = 998244353 mod = 943718401 root,iroot,rate2,irate2,rate3,irate3 = prepared_fft(mod) CC = convolute(A,B) def inv_gcd(a,b): a=a%b if a==0: return (b,0) s=b;t=a m0=0;m1=1 while(t): u=s//t s-=t*u m0-=m1*u s,t=t,s m0,m1=m1,m0 if m0<0: m0+=b//s return (s,m0) def inv_mod(x,m): assert 1<=m z=inv_gcd(x,m) assert z[0]==1 return z[1] def crt(r,m): assert len(r)==len(m) n=len(r) r0=0;m0=1 for i in range(n): assert 1<=m[i] r1=r[i]%m[i] m1=m[i] if m0<m1: r0,r1=r1,r0 m0,m1=m1,m0 if (m0%m1==0): if (r0%m1!=r1): return (0,0) continue g,im=inv_gcd(m0,m1) u1=m1//g if ((r1-r0)%g): return (0,0) x=(r1-r0)//g % u1*im%u1 r0+=x*m0 m0*=u1 if r0<0: r0+=m0 return (r0,m0) m = [mod1,mod] for i in range(N): r = [C[i],CC[i]] x = crt(r,m)[0] print(x)