結果

問題 No.2313 Product of Subsequence (hard)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-11-22 13:30:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,638 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 193,480 KB
最終ジャッジ日時 2023-11-22 13:31:13
合計ジャッジ時間 13,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
124,872 KB
testcase_01 AC 127 ms
124,872 KB
testcase_02 AC 128 ms
126,956 KB
testcase_03 AC 175 ms
137,736 KB
testcase_04 AC 182 ms
137,468 KB
testcase_05 AC 203 ms
137,344 KB
testcase_06 AC 163 ms
137,992 KB
testcase_07 AC 185 ms
137,352 KB
testcase_08 AC 1,591 ms
190,108 KB
testcase_09 AC 370 ms
161,820 KB
testcase_10 AC 883 ms
193,480 KB
testcase_11 AC 383 ms
141,220 KB
testcase_12 AC 760 ms
165,232 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
def md(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
    return lower_divisors + upper_divisors[::-1]
    
class combination():
    
    def __init__(self,N,p):
        
        
        self.fact = [1, 1]  # fact[n] = (n! mod p)
        self.factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        self.inv = [0, 1]  # factinv 計算用
        self.p = p
        
        for i in range(2, N + 1):
            self.fact.append((self.fact[-1] * i) % p)
            self.inv.append((-self.inv[p % i] * (p // i)) % p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % p)
        

    def cmb(self,n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.p    
C = combination(3*10**5,mod)
P = md(K)
n = len(P)
P.sort()
inv = {p:i for i,p in enumerate(P)}
A = [math.gcd(a,K) for a in A]
T = Counter(A)
N = len(T)
dp = [[0]*n for _ in range(len(T)+1)]
dp[0][0] = 1


idx = 0
for k,v in T.items():
    
    
    for j in range(n-1,-1,-1):
        p = P[j]
        res = 1
        for _ in range(v,-1,-1):
            jdx = inv[math.gcd(p*res,K)]
            dp[idx+1][jdx] = (dp[idx+1][jdx] + dp[idx][inv[p]]*C.cmb(v,_))%mod
            res = math.gcd(res*k,K)
    idx += 1
print(dp[-1][-1])
            
        
0