結果

問題 No.127 門松もどき
ユーザー gigurururugigurururu
提出日時 2015-01-15 23:28:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,215 ms / 5,000 ms
コード長 307 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 156,216 KB
最終ジャッジ日時 2023-08-25 13:46:06
合計ジャッジ時間 25,476 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,224 KB
testcase_01 AC 81 ms
15,060 KB
testcase_02 AC 81 ms
15,164 KB
testcase_03 AC 81 ms
15,068 KB
testcase_04 AC 2,215 ms
156,036 KB
testcase_05 AC 80 ms
15,124 KB
testcase_06 AC 207 ms
26,216 KB
testcase_07 AC 82 ms
15,228 KB
testcase_08 AC 81 ms
15,312 KB
testcase_09 AC 81 ms
15,156 KB
testcase_10 AC 80 ms
15,332 KB
testcase_11 AC 85 ms
15,368 KB
testcase_12 AC 1,091 ms
89,420 KB
testcase_13 AC 1,509 ms
114,812 KB
testcase_14 AC 1,374 ms
105,956 KB
testcase_15 AC 1,925 ms
141,372 KB
testcase_16 AC 1,301 ms
103,208 KB
testcase_17 AC 1,566 ms
117,328 KB
testcase_18 AC 1,247 ms
99,532 KB
testcase_19 AC 741 ms
66,712 KB
testcase_20 AC 764 ms
68,120 KB
testcase_21 AC 364 ms
39,404 KB
testcase_22 AC 2,209 ms
156,216 KB
testcase_23 AC 2,208 ms
156,004 KB
testcase_24 AC 1,639 ms
123,072 KB
testcase_25 AC 1,956 ms
142,872 KB
testcase_26 AC 939 ms
77,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
A=gets.split.map(&:to_i)
dp=[0,1].map{(1..N).map{[1]*N}}
(1...N).each{|d|
  (0...N-d).each{|l|
    r=l+d
    dpl=dp[0][l][r-1]
    dpr=dp[1][l+1][r]
    dp[0][l][r]=A[l]>=A[r]?dpl:[dpl,dpr+1].max
    dp[1][l][r]=A[l]<=A[r]?dpr:[dpr,dpl+1].max
  }
}
p ((0...N).map{|i|dp[0][i][N-1]}+dp[1][0]).max
0