結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:36:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,747 ms / 2,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 581 ms |
コンパイル使用メモリ | 81,928 KB |
実行使用メモリ | 142,364 KB |
最終ジャッジ日時 | 2025-04-15 22:37:41 |
合計ジャッジ時間 | 3,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import math import sys def main(): input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:N+1])) max_a = 3 * 10**5 max_dp = [0] * (max_a + 2) # To handle values up to 3e5 global_max = 0 for x in A: divisors = set() if x != 1: sqrt_x = int(math.sqrt(x)) for i in range(1, sqrt_x + 1): if x % i == 0: if i < x: divisors.add(i) j = x // i if j != i and j < x: divisors.add(j) current_max = 0 for d in divisors: if max_dp[d] > current_max: current_max = max_dp[d] dp_i = current_max + 1 if dp_i > max_dp[x]: max_dp[x] = dp_i if dp_i > global_max: global_max = dp_i print(global_max) if __name__ == "__main__": main()