結果

問題 No.2218 Multiple LIS
ユーザー HimaHima
提出日時 2023-03-02 21:54:29
言語 Go
(1.22.1)
結果
AC  
実行時間 1,082 ms / 3,000 ms
コード長 1,334 bytes
コンパイル時間 13,045 ms
コンパイル使用メモリ 214,340 KB
実行使用メモリ 21,136 KB
最終ジャッジ日時 2023-10-17 17:43:37
合計ジャッジ時間 20,187 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,764 KB
testcase_01 AC 2 ms
5,760 KB
testcase_02 AC 2 ms
5,760 KB
testcase_03 AC 2 ms
5,760 KB
testcase_04 AC 2 ms
5,760 KB
testcase_05 AC 2 ms
5,760 KB
testcase_06 AC 2 ms
5,760 KB
testcase_07 AC 2 ms
5,760 KB
testcase_08 AC 2 ms
5,760 KB
testcase_09 AC 2 ms
5,760 KB
testcase_10 AC 2 ms
5,760 KB
testcase_11 AC 2 ms
5,764 KB
testcase_12 AC 2 ms
5,772 KB
testcase_13 AC 4 ms
7,852 KB
testcase_14 AC 3 ms
5,804 KB
testcase_15 AC 3 ms
5,812 KB
testcase_16 AC 2 ms
5,772 KB
testcase_17 AC 4 ms
7,852 KB
testcase_18 AC 3 ms
5,764 KB
testcase_19 AC 2 ms
5,780 KB
testcase_20 AC 3 ms
5,808 KB
testcase_21 AC 31 ms
9,056 KB
testcase_22 AC 180 ms
17,480 KB
testcase_23 AC 301 ms
19,004 KB
testcase_24 AC 65 ms
12,916 KB
testcase_25 AC 331 ms
19,220 KB
testcase_26 AC 474 ms
21,124 KB
testcase_27 AC 476 ms
21,136 KB
testcase_28 AC 472 ms
20,108 KB
testcase_29 AC 469 ms
20,088 KB
testcase_30 AC 476 ms
20,100 KB
testcase_31 AC 224 ms
19,484 KB
testcase_32 AC 227 ms
21,032 KB
testcase_33 AC 223 ms
20,008 KB
testcase_34 AC 227 ms
20,012 KB
testcase_35 AC 221 ms
21,032 KB
testcase_36 AC 37 ms
16,360 KB
testcase_37 AC 1,082 ms
20,588 KB
testcase_38 AC 2 ms
5,760 KB
testcase_39 AC 2 ms
5,760 KB
testcase_40 AC 598 ms
21,004 KB
testcase_41 AC 598 ms
20,740 KB
権限があれば一括ダウンロードができます

ソースコード

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([]int, int(1e5)+1) //make(map[int]int)
	for i := 1; i <= n; i++ {
		d := divide(a[i-1])
		mx := 1
		for _, v := range d {
			mx = Max(mx, dp[v]+1)
		}
		dp[a[i-1]] = mx
	}
	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