結果

問題 No.2218 Multiple LIS
ユーザー HimaHima
提出日時 2023-03-02 21:38:55
言語 Go
(1.22.1)
結果
MLE  
実行時間 -
コード長 1,515 bytes
コンパイル時間 17,214 ms
コンパイル使用メモリ 221,624 KB
実行使用メモリ 814,896 KB
最終ジャッジ日時 2023-10-17 17:32:44
合計ジャッジ時間 22,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,624 KB
testcase_01 AC 2 ms
5,620 KB
testcase_02 AC 2 ms
5,624 KB
testcase_03 AC 2 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
4,348 KB
testcase_12 AC 7 ms
5,216 KB
testcase_13 AC 23 ms
12,640 KB
testcase_14 AC 17 ms
8,572 KB
testcase_15 AC 18 ms
8,908 KB
testcase_16 AC 5 ms
4,664 KB
testcase_17 AC 27 ms
11,928 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 5 ms
4,772 KB
testcase_20 AC 18 ms
9,288 KB
testcase_21 MLE -
testcase_22 MLE -
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, n+1)
	dp[0] = make(map[int]int)
	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = make(map[int]int)
		for k := range dp[i-1] {
			dp[i][k] = dp[i-1][k]
		}
		d := divide(a[i-1])
		d = append([]int{0}, d...)
		for _, v := range d {
			if _, found := dp[i-1][v]; found {
				dp[i][a[i-1]] = Max(dp[i][a[i-1]], dp[i-1][v]+1)
			}
		}
	}
	var ans int
	for _, v := range dp[n] {
		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