結果

問題 No.127 門松もどき
ユーザー aru aruaru aru
提出日時 2020-08-14 11:56:31
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,515 bytes
コンパイル時間 11,330 ms
コンパイル使用メモリ 241,976 KB
実行使用メモリ 10,280 KB
最終ジャッジ日時 2024-04-18 18:24:38
合計ジャッジ時間 18,301 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,784 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 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

func rec(l, r, lr int) int {
	// out(l, r, lr)
	if l < 0 || r >= N {
		return 0
	}
	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)
			}
		}
	}
	return ret
}

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

	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