結果

問題 No.1731 Product of Subsequence
ユーザー HydruHydru
提出日時 2021-11-06 13:29:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 588 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 166,132 KB
最終ジャッジ日時 2024-04-25 00:20:20
合計ジャッジ時間 12,152 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 47 ms
53,632 KB
testcase_02 AC 46 ms
53,760 KB
testcase_03 AC 47 ms
53,504 KB
testcase_04 AC 46 ms
54,016 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 47 ms
53,632 KB
testcase_08 WA -
testcase_09 AC 49 ms
53,760 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 55 ms
61,440 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 47 ms
53,760 KB
testcase_16 AC 47 ms
53,504 KB
testcase_17 AC 47 ms
53,888 KB
testcase_18 AC 832 ms
155,648 KB
testcase_19 WA -
testcase_20 AC 721 ms
144,256 KB
testcase_21 WA -
testcase_22 AC 79 ms
70,016 KB
testcase_23 AC 46 ms
53,760 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 78 ms
70,272 KB
testcase_32 AC 47 ms
53,632 KB
testcase_33 AC 79 ms
70,400 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import exit
from math import gcd
from collections import defaultdict
mod=10**9+7
n,k=map(int,input().split())
if k==1:
    print(pow(2,n,mod)-1)
    exit()

A=list(map(lambda x:gcd(int(x),k),input().split()))
B=[]
cnt=0
for x in A:
    if x==1:
        cnt+=1
    else:
        B.append(x)

m=len(B)
dp=[defaultdict(int) for _ in range(m+1)]
dp[0][1]=1
for i in range(1,m+1):
    for j in dp[i-1]:
        dp[i][j]+=dp[i-1][j]
        dp[i][j]%=mod

        ai=B[i-1]
        g=gcd(j*ai,k)
        dp[i][g]+=dp[i-1][j]
        dp[i][g]%=mod
ans=dp[m][k]*pow(2,cnt,mod)
print(ans)
0