結果

問題 No.979 Longest Divisor Sequence
ユーザー Salmonize
提出日時 2020-08-17 09:40:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,516 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 94,968 KB
最終ジャッジ日時 2024-10-11 10:51:24
合計ジャッジ時間 4,376 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
    n = ni()
    a = nl()
    s = set(a)
    m = max(a) + 5
    g = [[1] for _ in range(m)]
    for i in range(2, m):
        if i in s:
            for j in range(i*2, m, i):
                g[j].append(i)
    c = [-1]*m
    c[1] = 0
    for x in a:
        if x == 1:
            c[x] = 1
        else:
            c[x] = max([c[y] for y in g[x]]) + 1
    print(max(c))
    return

solve()
0