結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:17:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 959 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 82,720 KB |
| 実行使用メモリ | 140,852 KB |
| 最終ジャッジ日時 | 2025-03-20 21:18:10 |
| 合計ジャッジ時間 | 4,758 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 TLE * 1 |
ソースコード
import sys
import math
def get_divisors(x):
if x == 1:
return []
divisors = set()
x_sqrt = math.isqrt(x)
i = 1
while i <= x_sqrt:
if x % i == 0:
if i < x:
divisors.add(i)
j = x // i
if j < x and j != i:
divisors.add(j)
i += 1
return divisors
def main():
input = sys.stdin.read().split()
n = int(input[0])
A = list(map(int, input[1:n+1]))
dp = dict()
max_val = 0
for x in A:
divisors = get_divisors(x)
current_max = 0
for y in divisors:
if y in dp and dp[y] > current_max:
current_max = dp[y]
new_val = current_max + 1
if x in dp:
if new_val > dp[x]:
dp[x] = new_val
else:
dp[x] = new_val
if dp[x] > max_val:
max_val = dp[x]
print(max_val)
if __name__ == '__main__':
main()
lam6er