結果

問題 No.390 最長の数列
ユーザー yuki2006yuki2006
提出日時 2016-07-09 00:09:55
言語 Go
(1.22.1)
結果
AC  
実行時間 824 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 10,597 ms
コンパイル使用メモリ 235,516 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-04-10 08:53:40
合計ジャッジ時間 17,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,816 KB
testcase_01 AC 6 ms
6,812 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 816 ms
14,080 KB
testcase_06 AC 824 ms
18,172 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 817 ms
18,172 KB
testcase_11 AC 817 ms
18,172 KB
testcase_12 AC 824 ms
18,176 KB
testcase_13 AC 631 ms
16,076 KB
testcase_14 AC 718 ms
12,028 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 6 ms
11,744 KB
testcase_17 AC 42 ms
11,868 KB
testcase_18 AC 64 ms
11,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var N int
	const MAX = 1e6
	dp := make([]int, MAX + 1)
	fmt.Scan(&N)

	for i := 0; i < N; i++ {
		var x int
		fmt.Scan(&x)
		dp[x] = 1

	}
	for i := 1; i <= MAX; i++ {
		if dp[i] == 0 {
			continue
		}
		for l := 2 * i; l <= 1e6; l += i {
			if dp[l] == 0 {
				continue
			}

			dp[l] = max(dp[l], dp[i] + 1)
		}
	}
	mx := 0
	for i := 0; i <= MAX; i++ {
		mx = max(mx, dp[i])
	}
	fmt.Println(mx)
}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}
0