結果

問題 No.390 最長の数列
ユーザー hiyokko2hiyokko2
提出日時 2016-07-30 13:01:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 501 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,044 KB
最終ジャッジ日時 2024-04-24 13:06:06
合計ジャッジ時間 7,303 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
18,688 KB
testcase_01 WA -
testcase_02 AC 86 ms
18,688 KB
testcase_03 WA -
testcase_04 AC 88 ms
18,688 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def get_divisors(n):
	if n == 1:
		return []
	ret = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			ret.append(i)
			if i != 1 and i != n // i:
				ret.append(n // i)
	return ret

input()
xi = sorted(map(int, input().split()))

dp = [-99999 for _ in range(10**6 + 1)]
max_len = 0
for x in xi:
	di = get_divisors(x)
	if di == [1] and x != 1:
		dp[x] = 2
	elif x == 1:
		dp[x] = 1
	else:
		dp[x] = max([dp[d] for d in di]) + 1
	max_len = max(max_len, dp[x])
print(max_len)
0