結果
| 問題 |
No.390 最長の数列
|
| ユーザー |
buey_t
|
| 提出日時 | 2023-03-28 16:13:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 628 ms / 5,000 ms |
| コード長 | 2,709 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 160,076 KB |
| 最終ジャッジ日時 | 2024-09-20 05:55:10 |
| 合計ジャッジ時間 | 7,779 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
def main():
from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353
#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
'''
'''
class Eratosthenes:
def __init__(self, n):
self.isprime = [True] * (n + 1)
self.minfactor = [0] * (n + 1)
self.isprime[0], self.isprime[1] = False, False
self.minfactor[0], self.minfactor[1] = -1, -1
for i in range(2, n + 1):
if not self.isprime[i]:
continue
self.minfactor[i] = i
for j in range(i * i, n + 1, i):
self.isprime[j] = False
if self.minfactor[j] == 0:
self.minfactor[j] = i
def factorize(self, n):
factors = []
while n > 1:
p = self.minfactor[n]
cnt = 0
while n % p == 0:
n //= p
cnt += 1
factors.append((p, cnt))
return factors
def divisors(self, n):
res = [1]
pf = self.factorize(n)
for p in pf:
s = len(res)
for i in range(s):
v = 1
for j in range(p[1]):
v *= p[0]
res.append(res[i] * v)
return res
N = int(input())
X = list(map(int, input().split()))
er = Eratosthenes(10**6+1)
X.sort()
memo = defaultdict(int)
ans = 1
for i in range(N):
div = er.divisors(X[i])
memo[X[i]] = 1
for d in div:
if d == X[i]:
continue
memo[X[i]] = max(memo[X[i]],memo[d]+1)
ans = max(ans,memo[X[i]])
print(ans)
if __name__ == '__main__':
main()
buey_t