結果

問題 No.390 最長の数列
ユーザー yuki2006yuki2006
提出日時 2016-07-09 00:09:55
言語 Go
(1.21.3)
結果
AC  
実行時間 847 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 10,960 ms
コンパイル使用メモリ 212,100 KB
実行使用メモリ 18,404 KB
最終ジャッジ日時 2023-07-25 17:01:23
合計ジャッジ時間 17,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,644 KB
testcase_01 AC 6 ms
5,644 KB
testcase_02 AC 6 ms
5,644 KB
testcase_03 AC 6 ms
5,648 KB
testcase_04 AC 7 ms
5,644 KB
testcase_05 AC 839 ms
14,308 KB
testcase_06 AC 843 ms
18,400 KB
testcase_07 AC 5 ms
5,648 KB
testcase_08 AC 4 ms
5,644 KB
testcase_09 AC 5 ms
5,644 KB
testcase_10 AC 847 ms
18,400 KB
testcase_11 AC 840 ms
18,400 KB
testcase_12 AC 838 ms
18,404 KB
testcase_13 AC 647 ms
16,296 KB
testcase_14 AC 735 ms
12,256 KB
testcase_15 AC 4 ms
5,644 KB
testcase_16 AC 6 ms
11,788 KB
testcase_17 AC 43 ms
12,028 KB
testcase_18 AC 70 ms
12,036 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