結果

問題 No.390 最長の数列
ユーザー sue_charosue_charo
提出日時 2017-04-17 19:14:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,984 ms / 5,000 ms
コード長 821 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 25,188 KB
最終ジャッジ日時 2024-04-10 10:20:27
合計ジャッジ時間 5,533 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,520 KB
testcase_01 AC 35 ms
11,392 KB
testcase_02 AC 36 ms
11,520 KB
testcase_03 AC 40 ms
11,392 KB
testcase_04 AC 37 ms
11,392 KB
testcase_05 AC 174 ms
25,116 KB
testcase_06 AC 1,984 ms
25,024 KB
testcase_07 AC 37 ms
11,392 KB
testcase_08 AC 40 ms
19,164 KB
testcase_09 AC 89 ms
19,104 KB
testcase_10 AC 318 ms
25,176 KB
testcase_11 AC 337 ms
25,188 KB
testcase_12 AC 322 ms
25,180 KB
testcase_13 AC 320 ms
24,064 KB
testcase_14 AC 513 ms
21,916 KB
testcase_15 AC 37 ms
11,648 KB
testcase_16 AC 40 ms
19,104 KB
testcase_17 AC 46 ms
19,580 KB
testcase_18 AC 52 ms
19,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def solve(N, x):
    x.sort()
    num_max = max(x) + 1
    dp = [0] * num_max
    ans = 0
    for i in range(N):
        dp[x[i]] = 1
    for i in range(N):
        for j in range(x[i] * 2, num_max, x[i]):
            if dp[j] == 0:
                continue
            dp[j] = max(dp[j], dp[x[i]] + 1)
        ans = max(ans, dp[x[i]])
    
    return ans


def main():
    N = II()
    x = ILI()
    print(solve(N, x))


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