結果
問題 | No.2218 Multiple LIS |
ユーザー |
![]() |
提出日時 | 2023-02-17 22:24:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 291 ms / 3,000 ms |
コード長 | 1,181 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,664 KB |
実行使用メモリ | 91,300 KB |
最終ジャッジ日時 | 2024-07-19 13:32:56 |
合計ジャッジ時間 | 6,259 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
import sys input = sys.stdin.readline class tmp: def __init__(self, n_max:int=10**6): self.sieve = self.pre_factorization(n_max) def pre_factorization(self, n_max:int): sieve = [i for i in range(n_max+1)] p = 2 while p*p <= n_max: if sieve[p] == p: for q in range(2*p,n_max+1,p): if sieve[q] == q: sieve[q] = p p += 1 return sieve def factorization(self, n:int): tmp = {} while n > 1: i=self.sieve[n] tmp[i]=tmp.get(i,0)+1 n //= self.sieve[n] return tmp def divisors(self, n:int): res = [1] prime = self.factorization(n) for p in prime: newres = [] for d in res: for j in range(prime[p]+1): newres.append(d*p**j) res = newres res.sort() return res N=int(input()) A=list(map(int,input().split())) ans = [0]*(10**5+1) div = tmp(10**5) for a in A: x=0 for d in div.divisors(a): xx = ans[d] if xx>x: x=xx ans[a]=x+1 print(max(ans))