結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:34:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,712 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 82,508 KB |
実行使用メモリ | 142,300 KB |
最終ジャッジ日時 | 2025-04-15 22:35:59 |
合計ジャッジ時間 | 3,767 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
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()