結果

問題 No.390 最長の数列
ユーザー raven7959
提出日時 2021-09-01 07:10:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 516 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 165,444 KB
最終ジャッジ日時 2024-11-27 03:58:29
合計ジャッジ時間 44,936 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N=int(input())
A=list(map(int,input().split()))
G=[[] for _ in range(N)]
num=[0]*N
for i in range(N):
  for j in range(i+1,N):
    if A[j]>A[i] and A[j]%A[i]==0:
      G[i].append(j)
      num[j]+=1
    elif A[i]>A[j] and A[i]%A[j]==0:
      G[j].append(i)
      num[i]+=1
D=deque()
for i in range(N):
  if not num[i]:
    D.append(i)
DP=[1]*N
while D:
  v=D.popleft()
  for nv in G[v]:
    DP[nv]=max(DP[nv],DP[v]+1)
    num[nv]-=1
    if not num[nv]:
      D.append(nv)
print(max(DP))
0