結果

問題 No.2313 Product of Subsequence (hard)
ユーザー convexineqconvexineq
提出日時 2023-05-25 12:01:55
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 676 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 85,552 KB
実行使用メモリ 142,520 KB
最終ジャッジ日時 2023-09-28 13:56:35
合計ジャッジ時間 39,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,476 KB
testcase_01 AC 71 ms
71,300 KB
testcase_02 AC 72 ms
71,288 KB
testcase_03 AC 88 ms
76,500 KB
testcase_04 AC 82 ms
76,688 KB
testcase_05 AC 86 ms
76,616 KB
testcase_06 AC 81 ms
76,500 KB
testcase_07 AC 83 ms
76,540 KB
testcase_08 AC 349 ms
132,404 KB
testcase_09 AC 209 ms
96,976 KB
testcase_10 AC 316 ms
132,620 KB
testcase_11 AC 183 ms
94,656 KB
testcase_12 AC 347 ms
140,156 KB
testcase_13 TLE -
testcase_14 AC 3,951 ms
142,300 KB
testcase_15 AC 3,946 ms
142,348 KB
testcase_16 TLE -
testcase_17 AC 3,747 ms
140,116 KB
testcase_18 AC 3,839 ms
140,284 KB
testcase_19 AC 3,717 ms
141,056 KB
testcase_20 AC 3,745 ms
140,412 KB
testcase_21 AC 80 ms
75,744 KB
testcase_22 AC 76 ms
71,504 KB
testcase_23 AC 76 ms
71,232 KB
testcase_24 AC 74 ms
71,304 KB
testcase_25 AC 268 ms
133,796 KB
testcase_26 AC 200 ms
106,928 KB
testcase_27 AC 3,596 ms
142,204 KB
testcase_28 AC 292 ms
138,164 KB
testcase_29 AC 323 ms
140,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

n,k = map(int,readline().split())
*a, = map(int,readline().split())

from math import gcd
MOD = 998244353

div = []
for i in range(1,k+1):
    if i*i > k: break
    if k%i==0:
        div.append(i)
        if i*i < k:
            div.append(k//i)

div.sort()
za = {v:i for i,v in enumerate(div)}
L = len(za)

nxt = [[0]*L for _ in range(L)]
for i in range(L):
    for j in range(1,L):
        nxt[i][j] = nxt[j][i] = za[gcd(div[i]*div[j],k)]

dp = [0]*L
dp[0] = 1
for ai in a:
    idx = za[gcd(ai,k)]
    for i in range(L)[::-1]:
        nidx = nxt[idx][i]
        v = dp[i]
        dp[nidx] = (dp[nidx] + v)%MOD

print(dp[-1]-(k==1))
0