結果

問題 No.390 最長の数列
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-12 12:57:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 751 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 32,048 KB
最終ジャッジ日時 2024-04-22 15:21:31
合計ジャッジ時間 7,644 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 28 ms
11,008 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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