結果

問題 No.979 Longest Divisor Sequence
ユーザー lam6er
提出日時 2025-03-31 17:29:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,082 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 140,928 KB
最終ジャッジ日時 2025-03-31 17:30:34
合計ジャッジ時間 5,038 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def main():
    import sys
    input = sys.stdin.read().split()
    n = int(input[0])
    A = list(map(int, input[1:n+1]))
    
    max_dp = dict()
    ans = 0
    
    for x in A:
        divisors = set()
        if x != 1:
            sqrt_x = int(math.isqrt(x))
            for i in range(1, sqrt_x + 1):
                if x % i == 0:
                    divisors.add(i)
                    if i != 1:
                        other = x // i
                        divisors.add(other)
            divisors.discard(x)  # Ensure x is not in divisors
        # Now find the maximum dp among divisors
        current_max = 0
        for d in divisors:
            if d in max_dp and max_dp[d] > current_max:
                current_max = max_dp[d]
        dp_x = current_max + 1
        # Update max_dp for x
        if x in max_dp:
            if dp_x > max_dp[x]:
                max_dp[x] = dp_x
        else:
            max_dp[x] = dp_x
        # Update the answer
        if dp_x > ans:
            ans = dp_x
    print(ans)

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