結果
問題 | 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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 204 ms
105,728 KB |
testcase_01 | AC | 195 ms
105,472 KB |
testcase_02 | AC | 196 ms
105,728 KB |
testcase_03 | AC | 200 ms
105,644 KB |
testcase_04 | AC | 203 ms
105,472 KB |
testcase_05 | AC | 518 ms
160,076 KB |
testcase_06 | AC | 628 ms
123,408 KB |
testcase_07 | AC | 200 ms
105,472 KB |
testcase_08 | AC | 202 ms
105,856 KB |
testcase_09 | AC | 205 ms
105,984 KB |
testcase_10 | AC | 513 ms
136,188 KB |
testcase_11 | AC | 499 ms
137,140 KB |
testcase_12 | AC | 523 ms
140,432 KB |
testcase_13 | AC | 289 ms
116,352 KB |
testcase_14 | AC | 426 ms
119,996 KB |
testcase_15 | AC | 203 ms
105,472 KB |
testcase_16 | AC | 203 ms
105,520 KB |
testcase_17 | AC | 261 ms
108,732 KB |
testcase_18 | AC | 266 ms
110,788 KB |
ソースコード
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()