結果
問題 | No.1621 Sequence Inversions |
ユーザー | vwxyz |
提出日時 | 2022-05-03 10:15:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 331 ms / 3,000 ms |
コード長 | 2,440 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 128,000 KB |
最終ジャッジ日時 | 2024-07-02 12:49:21 |
合計ジャッジ時間 | 5,190 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,016 KB |
testcase_01 | AC | 42 ms
54,400 KB |
testcase_02 | AC | 82 ms
76,716 KB |
testcase_03 | AC | 46 ms
54,400 KB |
testcase_04 | AC | 42 ms
54,588 KB |
testcase_05 | AC | 42 ms
54,400 KB |
testcase_06 | AC | 53 ms
64,148 KB |
testcase_07 | AC | 71 ms
71,552 KB |
testcase_08 | AC | 273 ms
119,600 KB |
testcase_09 | AC | 330 ms
128,000 KB |
testcase_10 | AC | 331 ms
127,740 KB |
testcase_11 | AC | 272 ms
119,468 KB |
testcase_12 | AC | 185 ms
82,076 KB |
testcase_13 | AC | 177 ms
81,420 KB |
testcase_14 | AC | 168 ms
78,620 KB |
testcase_15 | AC | 232 ms
80,352 KB |
testcase_16 | AC | 199 ms
78,420 KB |
testcase_17 | AC | 225 ms
79,752 KB |
testcase_18 | AC | 192 ms
78,292 KB |
testcase_19 | AC | 85 ms
76,768 KB |
testcase_20 | AC | 139 ms
76,892 KB |
testcase_21 | AC | 229 ms
80,384 KB |
testcase_22 | AC | 230 ms
80,088 KB |
testcase_23 | AC | 225 ms
80,400 KB |
testcase_24 | AC | 44 ms
54,656 KB |
testcase_25 | AC | 46 ms
55,296 KB |
testcase_26 | AC | 42 ms
54,116 KB |
testcase_27 | AC | 43 ms
54,656 KB |
testcase_28 | AC | 44 ms
54,400 KB |
ソースコード
import sys from collections import Counter readline=sys.stdin.readline def NTT(polynomial0,polynomial1): if mod==998244353: prim_root=3 prim_root_inve=332748118 else: prim_root=Primitive_Root(mod) prim_root_inve=MOD(mod).Pow(prim_root,-1) def DFT(polynomial,n,inverse=False): if inverse: for bit in range(1,n+1): a=1<<bit-1 x=pow(prim_root,mod-1>>bit,mod) U=[1] for _ in range(a): U.append(U[-1]*x%mod) for i in range(1<<n-bit): for j in range(a): s=i*2*a+j t=s+a polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t]*U[j])%mod,(polynomial[s]-polynomial[t]*U[j])%mod x=pow((mod+1)//2,n,mod) for i in range(1<<n): polynomial[i]*=x polynomial[i]%=mod else: for bit in range(n,0,-1): a=1<<bit-1 x=pow(prim_root_inve,mod-1>>bit,mod) U=[1] for _ in range(a): U.append(U[-1]*x%mod) for i in range(1<<n-bit): for j in range(a): s=i*2*a+j t=s+a polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t])%mod,U[j]*(polynomial[s]-polynomial[t])%mod l=len(polynomial0)+len(polynomial1)-1 n=(len(polynomial0)+len(polynomial1)-2).bit_length() polynomial0=polynomial0+[0]*((1<<n)-len(polynomial0)) polynomial1=polynomial1+[0]*((1<<n)-len(polynomial1)) DFT(polynomial0,n) DFT(polynomial1,n) ntt=[x*y%mod for x,y in zip(polynomial0,polynomial1)] DFT(ntt,n,inverse=True) ntt=ntt[:l] return ntt N,K=map(int,readline().split()) A=list(map(int,readline().split())) mod=998244353 C=Counter(A) DP=[1] s=0 for a in sorted(list(C.keys())): c=C[a] dp=[[[0]*(s*c+1) for j in range(c+1)] for i in range(s+1)] dp[0][0][0]=1 for i in range(s+1): for j in range(c+1): for k in range(s*c+1): if i: dp[i][j][k]+=dp[i-1][j][k] if j and k-i>=0: dp[i][j][k]+=dp[i][j-1][k-i] dp[i][j][k]%=mod DP=NTT(DP,dp[-1][-1]) s+=c if len(DP)<=K: ans=0 else: ans=DP[K] print(ans)