結果

問題 No.2218 Multiple LIS
ユーザー rlangevin
提出日時 2024-04-14 20:03:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,241 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 234,144 KB
最終ジャッジ日時 2024-10-03 22:24:06
合計ジャッジ時間 6,967 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

class Divisor():
    def __init__(self, N):
        self.L = list(range(N + 1))
        for i in range(2, N + 1):
            if i != self.L[i]:
                continue
            for j in range(2 * i, N + 1, i):
                self.L[j] = i

    def factorize(self, n):
        if n <= 1:
            return []
        D = []
        while n != 1:
            cnt = 0
            now = self.L[n]
            while n % now == 0:
                cnt += 1
                n //= now
            D.append((now, cnt))
        return D

    def div(self, n):
        A = self.factorize(n)
        now = [1]
        for k, v in A:
            M = len(now)
            for i in range(M):
                x = now[i]
                for _ in range(v):
                    x *= k
                    now.append(x)
        return now


N = int(input())
A = list(map(int, input().split()))
D = Divisor(10**5+5)
pre = defaultdict(lambda : -10)
pre[1] = 0
for a in A:
    dp = defaultdict(lambda : -10)
    for d in D.div(a):
        dp[a] = max(dp[a], pre[d] + 1)
    for k, v in pre.items():
        dp[k] = max(dp[k], v)
        
    dp, pre = pre, dp

ans = 0
for k, v in pre.items():
    ans = max(ans, v)
    
print(ans)
0