結果

問題 No.979 Longest Divisor Sequence
コンテスト
ユーザー aaaaaaaaaa2230
提出日時 2022-04-16 14:29:58
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,750 ms / 2,000 ms
+ 537µs
コード長 651 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 93 ms
コンパイル使用メモリ 64,760 KB
実行使用メモリ 165,364 KB
最終ジャッジ日時 2026-10-20 04:51:02
合計ジャッジ時間 6,448 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import bisect

n = int(input())
A = list(map(int,input().split()))
M = 3*10**5+5
count = [0]*M
for a in A:
    count[a] += 1

lis = [[] for i in range(M)]
for i in range(M)[::-1]:
    if count[i] == 0:
        continue
    for j in range(i*2,M,i):
        if count[j]:
            lis[j].append(i)

ans = [0]*n
res = [[] for i in range(M)]
sA = [[a,i] for i,a in enumerate(A)]
sA.sort()

for a,ind in sA:
    cand = 1
    for nex in lis[a]:
        if res[nex]:
            nind = bisect.bisect_left(res[nex],ind)
            if nind:
                cand = max(cand,ans[res[nex][nind-1]]+1)
    ans[ind] = cand
    res[a].append(ind)

print(max(ans))
0