結果

問題 No.390 最長の数列
ユーザー はむ吉🐹
提出日時 2016-07-12 12:57:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 751 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 41,716 KB
最終ジャッジ日時 2024-10-14 14:27:09
合計ジャッジ時間 7,382 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 1 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

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