結果
| 問題 | No.979 Longest Divisor Sequence |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:29:51 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 861 ms / 2,000 ms |
| コード長 | 1,082 bytes |
| 記録 | |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 95,980 KB |
| 実行使用メモリ | 148,136 KB |
| 最終ジャッジ日時 | 2026-07-08 04:22:10 |
| 合計ジャッジ時間 | 4,189 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
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()
lam6er