結果

問題 No.390 最長の数列
ユーザー tcltktcltk
提出日時 2021-01-20 04:00:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,917 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,388 KB
実行使用メモリ 106,108 KB
最終ジャッジ日時 2023-08-23 07:39:12
合計ジャッジ時間 14,349 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 230 ms
83,304 KB
testcase_01 AC 233 ms
83,144 KB
testcase_02 AC 229 ms
83,368 KB
testcase_03 AC 230 ms
83,336 KB
testcase_04 AC 231 ms
83,392 KB
testcase_05 AC 1,917 ms
105,768 KB
testcase_06 AC 1,324 ms
105,712 KB
testcase_07 AC 230 ms
83,408 KB
testcase_08 AC 237 ms
91,488 KB
testcase_09 AC 240 ms
91,348 KB
testcase_10 AC 1,422 ms
105,724 KB
testcase_11 AC 1,427 ms
105,856 KB
testcase_12 AC 1,453 ms
106,108 KB
testcase_13 AC 1,097 ms
103,348 KB
testcase_14 AC 778 ms
98,436 KB
testcase_15 AC 230 ms
84,036 KB
testcase_16 AC 242 ms
91,832 KB
testcase_17 AC 316 ms
94,040 KB
testcase_18 AC 346 ms
94,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """5
# 1 2 3 4 5
# """
# sys.stdin = io.StringIO(_INPUT)


def get_divisors(n):
    lower_divisors = []
    upper_divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    N = int(input())
    X = sorted(map(int, input().split()))

    MaxX = max(X)

    dp = [0 for _ in range(MaxX + 1)]

    for i in range(N):
        divs = get_divisors(X[i])
        v = 0
        for d in divs:
            if d < X[i]:
                v = max(v, dp[d])
        dp[X[i]] = v + 1

    print(max(dp))

if __name__ == '__main__':
    main()
0