結果

問題 No.390 最長の数列
コンテスト
ユーザー AEn
提出日時 2022-05-16 21:20:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 504 ms / 5,000 ms
コード長 566 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 174 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 124,672 KB
最終ジャッジ日時 2026-04-04 13:07:16
合計ジャッジ時間 4,209 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

N = int(input())
S = list(map(int, input().split()))
S.sort()
s = set(S)
d = defaultdict(int)
if N == 1:
    print(1)
    exit()

for ss in S:
    d[ss] = 1

def yaku(X):
    res = 1
    for i in range(1, X+1):
        if i*i > X:
            break
        if X%i == 0:
            if i in s:
                res = max(res, d[i]+1)
            if i*i != X and X//i in s and X//i != X:
                res = max(res, d[X//i]+1)
    d[X] = res
    return res

ans = 0
for i in range(1, N):
    ans = max(ans, yaku(S[i]))
print(ans)
0