結果

問題 No.979 Longest Divisor Sequence
ユーザー NoneNone
提出日時 2021-02-27 20:50:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,970 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 121,000 KB
最終ジャッジ日時 2024-04-10 15:50:22
合計ジャッジ時間 4,784 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,608 KB
testcase_01 AC 38 ms
53,224 KB
testcase_02 AC 41 ms
53,132 KB
testcase_03 AC 39 ms
53,788 KB
testcase_04 AC 35 ms
53,640 KB
testcase_05 AC 36 ms
52,620 KB
testcase_06 AC 36 ms
52,604 KB
testcase_07 AC 36 ms
53,216 KB
testcase_08 AC 37 ms
52,128 KB
testcase_09 AC 36 ms
53,084 KB
testcase_10 AC 84 ms
76,624 KB
testcase_11 AC 75 ms
74,280 KB
testcase_12 AC 83 ms
76,124 KB
testcase_13 AC 154 ms
121,000 KB
testcase_14 AC 1,970 ms
113,288 KB
testcase_15 AC 678 ms
92,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = sorted(list(table)) # 速度が欲しい時は消す
    return table
import sys
input = sys.stdin.readline
N=int(input())
A=list(map(int, input().split()))
dp=[-1]*(max(A) + 1)
dp[1]=0
for a in A:
    tmp=0
    for n in divisors(a):
        if n==a: continue
        if dp[n]==-1: continue
        tmp=max(tmp,dp[n])
    dp[a]=tmp+1
print(max(dp))
0