結果

問題 No.390 最長の数列
ユーザー fmhrfmhr
提出日時 2016-07-09 02:36:07
言語 Go
(1.22.1)
結果
AC  
実行時間 45 ms / 5,000 ms
コード長 753 bytes
コンパイル時間 12,813 ms
コンパイル使用メモリ 219,252 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2024-04-10 08:55:55
合計ジャッジ時間 12,307 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 4 ms
6,816 KB
testcase_02 AC 4 ms
6,812 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 11 ms
7,504 KB
testcase_06 AC 45 ms
11,728 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 18 ms
11,596 KB
testcase_11 AC 18 ms
11,596 KB
testcase_12 AC 18 ms
11,596 KB
testcase_13 AC 17 ms
11,596 KB
testcase_14 AC 35 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 4 ms
11,596 KB
testcase_17 AC 5 ms
11,596 KB
testcase_18 AC 5 ms
11,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	MAX := 1000002
	n := nextInt()
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = nextInt()
	}
	dp := make([]int, MAX)
	for _, s := range x {
		dp[s] = 1
	}
	ans := 0
	for i := 1; i < MAX; i++ {
		if dp[i] <= 0 {
			continue
		}
		for j := i * 2; j < MAX; j += i {
			if dp[j] >= 1 {
				dp[j] = max(dp[j], dp[i]+1)
			}
		}
		ans = max(ans, dp[i])
	}
	fmt.Println(ans)
}

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


var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
0