結果

問題 No.390 最長の数列
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-07-16 18:54:06
言語 Go
(1.22.1)
結果
AC  
実行時間 729 ms / 5,000 ms
コード長 501 bytes
コンパイル時間 10,898 ms
コンパイル使用メモリ 239,696 KB
実行使用メモリ 16,072 KB
最終ジャッジ日時 2024-04-10 09:11:59
合計ジャッジ時間 15,931 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 708 ms
11,968 KB
testcase_06 AC 729 ms
16,060 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 698 ms
16,056 KB
testcase_11 AC 678 ms
16,064 KB
testcase_12 AC 701 ms
16,060 KB
testcase_13 AC 541 ms
16,072 KB
testcase_14 AC 616 ms
7,828 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 4 ms
11,740 KB
testcase_17 AC 35 ms
11,752 KB
testcase_18 AC 55 ms
11,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

const MAX = 1000000

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	dp := make([]int, MAX+1)
	for _, v := range a {
		dp[v] = 1
	}
	ans := 1
	for i := 1; i < MAX+1; i++ {
		if dp[i] <= 0 {
			continue
		}
		for j := i+i; j < MAX+1; j+=i {
			if dp[j] != 0 {
				dp[j] = max(dp[i] + 1, dp[j])
			}
		}
		ans = max(dp[i], ans)
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
0