結果

問題 No.2218 Multiple LIS
ユーザー HimaHima
提出日時 2023-03-02 21:42:13
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,464 bytes
コンパイル時間 11,649 ms
コンパイル使用メモリ 214,268 KB
実行使用メモリ 24,620 KB
最終ジャッジ日時 2023-10-17 17:35:29
合計ジャッジ時間 19,318 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,972 KB
testcase_01 AC 2 ms
5,620 KB
testcase_02 AC 2 ms
5,624 KB
testcase_03 AC 3 ms
5,620 KB
testcase_04 AC 2 ms
5,620 KB
testcase_05 AC 2 ms
5,620 KB
testcase_06 AC 2 ms
5,620 KB
testcase_07 AC 2 ms
5,620 KB
testcase_08 AC 2 ms
5,620 KB
testcase_09 AC 2 ms
5,620 KB
testcase_10 AC 2 ms
5,620 KB
testcase_11 AC 2 ms
5,632 KB
testcase_12 AC 7 ms
6,752 KB
testcase_13 AC 23 ms
12,596 KB
testcase_14 AC 16 ms
10,100 KB
testcase_15 AC 17 ms
10,428 KB
testcase_16 AC 5 ms
6,204 KB
testcase_17 AC 25 ms
13,452 KB
testcase_18 AC 3 ms
5,848 KB
testcase_19 AC 6 ms
6,304 KB
testcase_20 AC 19 ms
10,820 KB
testcase_21 AC 1,974 ms
20,092 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	//bufサイズ以上の文字列入力が必要な場合は拡張すること
	buf := make([]byte, 9*1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := nextIntSlice(n)
	ans := solve(n, a)
	PrintInt(ans)
}

func divide(x int) []int {
	m := make(map[int]struct{})
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			m[i] = struct{}{}
			m[x/i] = struct{}{}
		}
	}
	var res []int
	for k := range m {
		res = append(res, k)
	}
	sort.Ints(res)
	return res

}
func solve(n int, a []int) int {
	dp := make(map[int]int)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		next := make(map[int]int)
		for k := range dp {
			next[k] = dp[k]
		}
		d := divide(a[i-1])
		d = append([]int{0}, d...)
		for _, v := range d {
			if _, found := dp[v]; found {
				next[a[i-1]] = Max(next[a[i-1]], dp[v]+1)
			}
		}
		dp = next
	}
	var ans int
	for _, v := range dp {
		ans = Max(ans, v)
	}
	return ans
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

func nextIntSlice(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = nextInt()
	}
	return s
}

func PrintInt(x int) {
	defer out.Flush()
	fmt.Fprintln(out, x)
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}
0