結果

問題 No.979 Longest Divisor Sequence
ユーザー convexineqconvexineq
提出日時 2020-01-31 23:21:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,423 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 131,592 KB
最終ジャッジ日時 2023-10-17 12:36:00
合計ジャッジ時間 3,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
59,432 KB
testcase_01 AC 49 ms
59,448 KB
testcase_02 AC 50 ms
59,448 KB
testcase_03 AC 47 ms
59,436 KB
testcase_04 AC 50 ms
59,436 KB
testcase_05 AC 49 ms
59,436 KB
testcase_06 AC 51 ms
59,436 KB
testcase_07 AC 49 ms
59,436 KB
testcase_08 AC 56 ms
59,448 KB
testcase_09 AC 52 ms
59,588 KB
testcase_10 AC 72 ms
70,564 KB
testcase_11 AC 65 ms
68,528 KB
testcase_12 AC 63 ms
68,528 KB
testcase_13 AC 120 ms
131,592 KB
testcase_14 AC 1,423 ms
128,796 KB
testcase_15 AC 436 ms
107,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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))

0