結果

問題 No.979 Longest Divisor Sequence
ユーザー convexineqconvexineq
提出日時 2020-01-31 23:15:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,659 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 81,428 KB
実行使用メモリ 147,284 KB
最終ジャッジ日時 2023-10-17 12:23:41
合計ジャッジ時間 4,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,596 KB
testcase_01 AC 42 ms
59,608 KB
testcase_02 AC 43 ms
59,608 KB
testcase_03 AC 40 ms
59,596 KB
testcase_04 AC 44 ms
59,596 KB
testcase_05 AC 43 ms
59,596 KB
testcase_06 AC 45 ms
59,596 KB
testcase_07 AC 47 ms
59,596 KB
testcase_08 AC 48 ms
59,608 KB
testcase_09 AC 45 ms
59,624 KB
testcase_10 AC 91 ms
76,660 KB
testcase_11 AC 76 ms
76,548 KB
testcase_12 AC 74 ms
76,648 KB
testcase_13 AC 246 ms
147,284 KB
testcase_14 AC 1,659 ms
136,928 KB
testcase_15 AC 498 ms
107,844 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]

sa = sorted([(ai,i) for i,ai in enumerate(a)],key = lambda x: x[0])
from bisect import bisect_left
from itertools import groupby
for k,g in groupby(sa,key = lambda x: x[0]):
    c = sorted([[i,ans[i]] for a,i in g],key = lambda x: x[0])
    l = len(c)
    for i in range(1,l):
        c[i][1] = max(c[i][1],c[i-1][1])
    
    #print(k,c)
        
    for p in range(2*k,MAX,k):
        if p in d:
            for j in d[p]:
                idx = bisect_left(c,[j,-1])
                #print(k,p,idx,j,ans)
                if idx >= 1: 
                    ans[j] = max(ans[j],c[idx-1][1]+1)
    
    #print(ans)
    
print(max(ans))

0