結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
convexineq
|
| 提出日時 | 2020-01-31 23:21:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,468 ms / 2,000 ms |
| コード長 | 814 bytes |
| コンパイル時間 | 142 ms |
| コンパイル使用メモリ | 82,768 KB |
| 実行使用メモリ | 131,856 KB |
| 最終ジャッジ日時 | 2024-09-17 10:42:00 |
| 合計ジャッジ時間 | 3,550 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,*a = [int(i) for i in read().split()]
MAX = 1+3*10**5
#MAX = 20
ans = [1]*n
d = {}
for i,ai in enumerate(a):
if ai in d:
d[ai].append(i)
else:
d[ai] = [i]
from bisect import bisect_left
from itertools import groupby
for k in range(1,MAX):
if k not in d: continue
dk = d[k]
v = [ans[i] for i in dk]
l = len(v)
for i in range(1,l):
if v[i] < v[i-1]: v[i] = v[i-1]
#print(k,c)
for p in range(2*k,MAX,k):
if p in d:
for j in d[p]:
idx = bisect_left(dk,j)
#print(k,p,idx,j,ans)
if idx >= 1:
ans[j] = max(ans[j],v[idx-1]+1)
#print(ans)
print(max(ans))
convexineq