結果
問題 |
No.2218 Multiple LIS
|
ユーザー |
![]() |
提出日時 | 2024-04-14 20:11:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 258 ms / 3,000 ms |
コード長 | 1,075 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 93,568 KB |
最終ジャッジ日時 | 2024-10-03 22:37:05 |
合計ジャッジ時間 | 7,197 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
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(101010) dp = [-10] * 101010 dp[1] = 0 for a in A: for d in sorted(D.div(a), reverse=True): dp[a] = max(dp[a], dp[d] + 1) print(max(dp))