結果

問題 No.390 最長の数列
ユーザー roarisroaris
提出日時 2019-08-14 23:25:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,679 ms / 5,000 ms
コード長 604 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 81,600 KB
実行使用メモリ 123,292 KB
最終ジャッジ日時 2023-10-19 18:20:15
合計ジャッジ時間 9,985 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,692 KB
testcase_01 AC 43 ms
55,740 KB
testcase_02 AC 44 ms
55,740 KB
testcase_03 AC 43 ms
53,764 KB
testcase_04 AC 43 ms
55,740 KB
testcase_05 AC 1,679 ms
123,292 KB
testcase_06 AC 1,159 ms
112,472 KB
testcase_07 AC 43 ms
53,516 KB
testcase_08 AC 50 ms
67,104 KB
testcase_09 AC 50 ms
67,104 KB
testcase_10 AC 1,277 ms
112,900 KB
testcase_11 AC 1,269 ms
113,164 KB
testcase_12 AC 1,291 ms
113,368 KB
testcase_13 AC 849 ms
106,124 KB
testcase_14 AC 591 ms
106,048 KB
testcase_15 AC 46 ms
59,440 KB
testcase_16 AC 55 ms
69,908 KB
testcase_17 AC 126 ms
83,480 KB
testcase_18 AC 167 ms
87,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#貰うDP
from collections import defaultdict

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    return divisors
    
N = int(input())
x = list(map(int, input().split()))
x.sort()
flag = defaultdict(int)

for xi in x:
    flag[xi] = 1
    
A = max(x)
dp = [1] * (A+1)

for xi in x:
    divisors = make_divisors(xi)
    
    for div in divisors:
        if xi != div and flag[div]:
            dp[xi] = max(dp[xi], dp[div]+1)

ans = max(dp)
print(ans)
0