結果

問題 No.1731 Product of Subsequence
ユーザー 👑 KazunKazun
提出日時 2021-11-05 22:15:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,905 ms / 2,000 ms
コード長 2,530 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 77,164 KB
最終ジャッジ日時 2024-04-25 17:26:14
合計ジャッジ時間 23,646 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,790 ms
76,660 KB
testcase_01 AC 39 ms
53,948 KB
testcase_02 AC 39 ms
53,020 KB
testcase_03 AC 42 ms
60,032 KB
testcase_04 AC 40 ms
53,360 KB
testcase_05 AC 61 ms
70,216 KB
testcase_06 AC 56 ms
67,420 KB
testcase_07 AC 43 ms
59,976 KB
testcase_08 AC 153 ms
76,552 KB
testcase_09 AC 42 ms
59,308 KB
testcase_10 AC 1,644 ms
76,844 KB
testcase_11 AC 1,423 ms
76,688 KB
testcase_12 AC 70 ms
76,364 KB
testcase_13 AC 97 ms
76,744 KB
testcase_14 AC 1,477 ms
76,764 KB
testcase_15 AC 39 ms
53,340 KB
testcase_16 AC 38 ms
52,836 KB
testcase_17 AC 38 ms
53,600 KB
testcase_18 AC 1,760 ms
76,808 KB
testcase_19 AC 96 ms
76,296 KB
testcase_20 AC 1,441 ms
76,776 KB
testcase_21 AC 1,807 ms
76,848 KB
testcase_22 AC 1,905 ms
76,836 KB
testcase_23 AC 42 ms
60,172 KB
testcase_24 AC 113 ms
76,968 KB
testcase_25 AC 92 ms
76,652 KB
testcase_26 AC 341 ms
76,512 KB
testcase_27 AC 465 ms
76,688 KB
testcase_28 AC 905 ms
76,760 KB
testcase_29 AC 362 ms
76,564 KB
testcase_30 AC 1,834 ms
77,164 KB
testcase_31 AC 1,762 ms
76,716 KB
testcase_32 AC 41 ms
59,244 KB
testcase_33 AC 152 ms
76,476 KB
testcase_34 AC 172 ms
76,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#素因数分解
def Prime_Factorization(N):
    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)

    if N&1==0:
        C=0
        while N&1==0:
            N>>=1
            C+=1
        R.append([2,C])

    if N%3==0:
        C=0
        while N%3==0:
            N//=3
            C+=1
        R.append([3,C])

    k=5
    Flag=0
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=2+2*Flag
        Flag^=1

    if N!=1:
        R.append([N,1])

    return R

class Grid:
    def __init__(self,*F):
        self.F=tuple(F)
        self.dim=len(self.F)

        R=[1]
        for a in self.F[::-1]:
            R.append(R[-1]*a)

        self.volume,*self.partition=R[::-1]

    def number_to_position(self,N):
        assert 0<=N<self.volume

        pos=[0]*self.dim
        for i in range(self.dim):
            pos[i],N=divmod(N,self.partition[i])
        return pos

    def position_to_number(self,*pos):
        assert len(pos)==self.dim

        N=0
        for i in range(self.dim):
            assert 0<=pos[i]<self.F[i]
            N+=self.partition[i]*pos[i]
        return N

    def number_neighborhood_yielder(self,N):
        r=N
        for i in range(self.dim):
            q,r=divmod(r,self.partition[i])

            if 0<q:
                yield N-self.partition[i]

            if q<self.F[i]-1:
                yield N+self.partition[i]

    def position_neighborhood_yielder(self,*pos):
        assert self.dim==len(pos)
        pos=list(pos)

        for i in range(self.dim):
            if 0<pos[i]:
                pos[i]-=1
                yield pos
                pos[i]+=1

            if pos[i]<self.F[i]-1:
                pos[i]+=1
                yield pos
                pos[i]-=1

#==================================================
N,K=map(int,input().split())
A=list(map(int,input().split()))

Mod=10**9+7

if K==1:
    exit(print((pow(2,N,Mod)-1)%Mod))

P=[(p,e) for p,e in Prime_Factorization(K)]

tau=[e+1 for p,e in P]
m=len(P)
G=Grid(*tau)

k=1
for t in tau:
    k*=t

DP=[0]*k; DP[0]=1
q=[0]*m
for a in A:
    f=[0]*m
    for i in range(m):
        p,_=P[i]
        while a%p==0:
            f[i]+=1
            a//=p

    for j in range(k-1,-1,-1):
        p=G.number_to_position(j)
        for i in range(m):
            q[i]=min(p[i]+f[i],P[i][1])

        DP[G.position_to_number(*q)]+=DP[j]

    for j in range(k):
        DP[j]%=Mod

print(DP[-1])
0