結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:38:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,282 ms / 2,000 ms |
コード長 | 887 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 209,016 KB |
最終ジャッジ日時 | 2025-04-15 22:39:17 |
合計ジャッジ時間 | 14,743 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import sys def main(): input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:N+1])) max_A = 300000 # As per problem constraints # Precompute divisors for all x up to max_A divisors = [[] for _ in range(max_A + 1)] for d in range(1, max_A + 1): multiple = d * 2 while multiple <= max_A: divisors[multiple].append(d) multiple += d max_dp = dict() answer = 0 for x in A: current_max = 0 for d in divisors[x]: if d in max_dp and max_dp[d] > current_max: current_max = max_dp[d] dp = current_max + 1 if x in max_dp: if dp > max_dp[x]: max_dp[x] = dp else: max_dp[x] = dp if dp > answer: answer = dp print(answer) if __name__ == '__main__': main()