結果

問題 No.127 門松もどき
ユーザー aru aruaru aru
提出日時 2020-08-14 11:58:57
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,743 bytes
コンパイル時間 14,059 ms
コンパイル使用メモリ 248,080 KB
実行使用メモリ 147,584 KB
最終ジャッジ日時 2024-04-18 18:25:00
合計ジャッジ時間 18,664 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
142,336 KB
testcase_01 AC 68 ms
142,336 KB
testcase_02 AC 68 ms
142,336 KB
testcase_03 AC 69 ms
142,336 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

var N int
var A []int

var memo [3001][3001][2]int

func rec(l, r, lr int) int {
	// out(l, r, lr)
	if l < 0 || r >= N {
		return 0
	}
	if memo[l][r][lr] != -1 {
		return memo[l][r][lr]
	}
	ret := 0
	if lr == 0 {
		for i := r; i < N; i++ {
			if A[i] < A[l] {
				ret = max(ret, rec(l, i, 1)+1)
			}
		}
	} else {
		for i := l; i >= 0; i-- {
			if A[i] < A[r] {
				ret = max(ret, rec(i, r, 0)+1)
			}
		}
	}
	memo[l][r][lr] = ret
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N = getInt()
	A = getInts(N)

	for i := 0; i < 3001; i++ {
		for j := 0; j < 3001; j++ {
			for k := 0; k < 2; k++ {
				memo[i][j][k] = -1
			}
		}
	}

	ret := 0
	for i := 0; i < N; i++ {
		for j := 0; j < 2; j++ {
			ret = max(ret, rec(i, i, j))
		}
	}
	out(ret + 1)
}
0