結果

問題 No.979 Longest Divisor Sequence
ユーザー lilictakalilictaka
提出日時 2022-05-23 22:29:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,137 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 138,876 KB
最終ジャッジ日時 2023-10-20 17:45:19
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,500 KB
testcase_01 AC 42 ms
55,500 KB
testcase_02 AC 42 ms
55,500 KB
testcase_03 AC 41 ms
55,500 KB
testcase_04 AC 41 ms
55,500 KB
testcase_05 AC 39 ms
55,500 KB
testcase_06 AC 41 ms
55,500 KB
testcase_07 AC 40 ms
55,500 KB
testcase_08 AC 41 ms
55,500 KB
testcase_09 AC 42 ms
55,500 KB
testcase_10 AC 65 ms
78,088 KB
testcase_11 AC 87 ms
90,532 KB
testcase_12 AC 65 ms
79,092 KB
testcase_13 AC 113 ms
121,608 KB
testcase_14 AC 1,137 ms
138,876 KB
testcase_15 AC 290 ms
99,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
memo = [[] for _ in range(MAX+1)]
for i,a in enumerate(A):
    memo[a].append(i)
Aset = set()
dp = [1] * N
IND = [-1] * (MAX+1)
for i in range(N):
    ai = A[i]
    last = IND[ai]
    if last != -1 and dp[last] >= dp[i]:
        pass
    IND[ai] = i
    for m in range(2,(MAX//ai) + 1):
        if memo[ai * m] == []:
            continue
        index = bisect_left(memo[ai * m],i)
        if index == len(memo[ai * m]):
            continue
        nxi = memo[ai * m][index]
        dp[nxi] = max(dp[i] + 1,dp[nxi])
print(max(dp))
0