結果

問題 No.979 Longest Divisor Sequence
ユーザー lam6er
提出日時 2025-04-15 22:37:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,824 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 81,544 KB
実行使用メモリ 143,080 KB
最終ジャッジ日時 2025-04-15 22:38:00
合計ジャッジ時間 4,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def main():
    input = sys.stdin.read().split()
    n = int(input[0])
    a = list(map(int, input[1:n+1]))
    max_a = max(a)
    dp = [0] * (max_a + 1)
    max_len = 0
    
    for x in a:
        divisors = []
        if x != 1:
            sqrt_x = math.isqrt(x)
            for i in range(1, sqrt_x + 1):
                if x % i == 0:
                    if i < x:
                        divisors.append(i)
                    counterpart = x // i
                    if counterpart != i and counterpart < x:
                        divisors.append(counterpart)
        
        current_max = 0
        for d in divisors:
            if d <= max_a and dp[d] > current_max:
                current_max = dp[d]
        
        new_length = current_max + 1
        if new_length > dp[x]:
            dp[x] = new_length
        
        if dp[x] > max_len:
            max_len = dp[x]
    
    print(max_len)

if __name__ == '__main__':
    main()
0