結果
問題 | No.127 門松もどき |
ユーザー |
![]() |
提出日時 | 2020-08-14 12:17:06 |
言語 | Go (1.20.2) |
結果 |
AC
|
実行時間 | 132 ms / 5,000 ms |
コード長 | 1,569 bytes |
コンパイル時間 | 11,354 ms |
コンパイル使用メモリ | 216,164 KB |
実行使用メモリ | 147,512 KB |
最終ジャッジ日時 | 2023-07-31 18:23:49 |
合計ジャッジ時間 | 14,130 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,092 KB |
testcase_01 | AC | 4 ms
8,088 KB |
testcase_02 | AC | 5 ms
8,084 KB |
testcase_03 | AC | 5 ms
8,084 KB |
testcase_04 | AC | 132 ms
147,512 KB |
testcase_05 | AC | 5 ms
8,088 KB |
testcase_06 | AC | 19 ms
47,000 KB |
testcase_07 | AC | 6 ms
12,188 KB |
testcase_08 | AC | 5 ms
8,092 KB |
testcase_09 | AC | 4 ms
8,096 KB |
testcase_10 | AC | 5 ms
8,096 KB |
testcase_11 | AC | 6 ms
14,240 KB |
testcase_12 | AC | 77 ms
110,648 KB |
testcase_13 | AC | 98 ms
127,036 KB |
testcase_14 | AC | 91 ms
122,940 KB |
testcase_15 | AC | 120 ms
143,416 KB |
testcase_16 | AC | 88 ms
118,844 KB |
testcase_17 | AC | 99 ms
127,032 KB |
testcase_18 | AC | 86 ms
118,840 KB |
testcase_19 | AC | 57 ms
94,220 KB |
testcase_20 | AC | 58 ms
94,224 KB |
testcase_21 | AC | 31 ms
65,492 KB |
testcase_22 | AC | 131 ms
147,512 KB |
testcase_23 | AC | 130 ms
147,512 KB |
testcase_24 | AC | 104 ms
131,132 KB |
testcase_25 | AC | 120 ms
143,420 KB |
testcase_26 | AC | 66 ms
102,456 KB |
ソースコード
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 } func main() { sc.Split(bufio.ScanWords) N := getInt() A := getInts(N) var dpL [3030][3030]int var dpR [3030][3030]int for i := 0; i < N; i++ { dpL[i][i] = 1 dpR[i][i] = 1 } for n := 1; n < N; n++ { for i := 0; i < N-n; i++ { j := i + n dpL[i][j] = dpL[i][j-1] dpR[i][j] = dpR[i+1][j] if A[i] < A[j] { dpL[i][j] = max(dpL[i][j], dpR[i+1][j]+1) } if A[i] > A[j] { dpR[i][j] = max(dpR[i][j], dpL[i][j-1]+1) } } } ans := 0 for i := 0; i < N; i++ { for j := i; j < N; j++ { ans = max(ans, max(dpL[i][j], dpR[i][j])) } } out(ans) }