結果

問題 No.390 最長の数列
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-12 12:58:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,741 ms / 5,000 ms
コード長 749 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 117,004 KB
最終ジャッジ日時 2024-04-22 15:21:56
合計ジャッジ時間 14,999 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,016 KB
testcase_01 AC 46 ms
54,144 KB
testcase_02 AC 45 ms
53,888 KB
testcase_03 AC 45 ms
53,760 KB
testcase_04 AC 45 ms
54,400 KB
testcase_05 AC 2,741 ms
117,004 KB
testcase_06 AC 1,885 ms
93,116 KB
testcase_07 AC 46 ms
54,016 KB
testcase_08 AC 46 ms
54,272 KB
testcase_09 AC 46 ms
54,528 KB
testcase_10 AC 1,980 ms
104,112 KB
testcase_11 AC 1,962 ms
103,728 KB
testcase_12 AC 1,959 ms
103,732 KB
testcase_13 AC 1,349 ms
86,648 KB
testcase_14 AC 757 ms
90,340 KB
testcase_15 AC 46 ms
53,888 KB
testcase_16 AC 54 ms
60,800 KB
testcase_17 AC 159 ms
80,000 KB
testcase_18 AC 215 ms
81,152 KB
権限があれば一括ダウンロードができます

ソースコード

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