結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 15:51:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,012 ms / 2,000 ms |
| コード長 | 887 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 82,400 KB |
| 実行使用メモリ | 208,408 KB |
| 最終ジャッジ日時 | 2025-04-16 15:52:15 |
| 合計ジャッジ時間 | 11,815 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()
lam6er