結果

問題 No.979 Longest Divisor Sequence
ユーザー 👑 naipianaipia
提出日時 2020-01-31 23:45:31
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,543 bytes
コンパイル時間 16,159 ms
コンパイル使用メモリ 210,912 KB
実行使用メモリ 15,200 KB
最終ジャッジ日時 2023-10-17 13:13:13
合計ジャッジ時間 18,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 1,723 ms
15,200 KB
testcase_15 AC 555 ms
8,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

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

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

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪( -ω-)ノ ( ・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	a := scanInts(n)

	ldi := make(map[int]int, 0)

	for i := 0; i < n; i++ {
		for j := 1; j*j <= a[i]; j++ {
			if a[i]%j == 0 {
				ldi[a[i]] = max(ldi[a[i]], ldi[j]+1)
				if j != 1 {
					ldi[a[i]] = max(ldi[a[i]], ldi[a[i]/j]+1)
				}
			}
		}
		// fmt.Println(ldi)
	}

	ans := 0
	for _, e := range ldi {
		ans = max(ans, e)
	}
	fmt.Println(ans)
	// fmt.Println(ldi)
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}
0