結果

問題 No.390 最長の数列
ユーザー はむ吉🐹
提出日時 2016-07-12 12:58:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,464 ms / 5,000 ms
コード長 749 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 117,208 KB
最終ジャッジ日時 2024-10-14 14:27:32
合計ジャッジ時間 13,626 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import array
import collections
import math


def divisors_without_self(n):
    ds = set()
    if n != 1:
        for i in range(1, math.floor(math.sqrt(n)) + 1):
            r, m = divmod(n, i)
            if m == 0:
                ds.add(i)
                if i != 1 and i != r:
                    ds.add(r)
    return ds


def calc_len_of_longest_good_seq(xs):
    dp = collections.defaultdict(int)
    for x in sorted(xs):
        dp[x] = 1
        for y in divisors_without_self(x):
            dp[x] = max(dp[x], dp[y] + 1)
    return max(dp.values())


def main():
    _ = input()
    xs = array.array("L", map(int, input().split()))
    print(calc_len_of_longest_good_seq(xs))


if __name__ == '__main__':
    main()
0