結果

問題 No.979 Longest Divisor Sequence
ユーザー stngstng
提出日時 2022-08-17 10:13:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,751 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 109,916 KB
最終ジャッジ日時 2024-04-15 01:47:37
合計ジャッジ時間 3,895 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,664 KB
testcase_01 AC 37 ms
52,940 KB
testcase_02 AC 37 ms
52,448 KB
testcase_03 AC 37 ms
53,480 KB
testcase_04 AC 38 ms
52,592 KB
testcase_05 AC 38 ms
52,868 KB
testcase_06 AC 37 ms
52,872 KB
testcase_07 AC 37 ms
53,408 KB
testcase_08 AC 37 ms
52,716 KB
testcase_09 AC 38 ms
53,464 KB
testcase_10 AC 78 ms
73,324 KB
testcase_11 AC 71 ms
70,100 KB
testcase_12 AC 74 ms
71,200 KB
testcase_13 AC 85 ms
102,300 KB
testcase_14 AC 1,751 ms
109,916 KB
testcase_15 AC 625 ms
87,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i == 1:
                continue
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors#[:-1]

n = int(input())
a = [int(i) for i in input().split()]

dp = [0]*(max(a)+1)

for i in range(n):
    if a[i] == 1:
        div = []
    else:
        div = make_divisors(a[i])
    tmp = 0
    #print(a[i],div)
    for j in range(len(div)):
        #print(div[j],j)
        tmp = max(tmp,dp[div[j]])
    dp[a[i]] = max(dp[a[i]],tmp+1)

print(max(dp))
0