結果

問題 No.127 門松もどき
ユーザー gigurururugigurururu
提出日時 2015-01-15 19:54:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,599 ms / 5,000 ms
コード長 424 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 192,788 KB
最終ジャッジ日時 2023-08-25 13:44:48
合計ジャッジ時間 29,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,244 KB
testcase_01 AC 81 ms
15,284 KB
testcase_02 AC 81 ms
15,112 KB
testcase_03 AC 79 ms
15,128 KB
testcase_04 AC 2,591 ms
191,480 KB
testcase_05 AC 80 ms
15,208 KB
testcase_06 AC 243 ms
30,860 KB
testcase_07 AC 82 ms
15,512 KB
testcase_08 AC 80 ms
15,236 KB
testcase_09 AC 78 ms
15,256 KB
testcase_10 AC 80 ms
15,008 KB
testcase_11 AC 83 ms
15,868 KB
testcase_12 AC 1,252 ms
111,108 KB
testcase_13 AC 1,610 ms
143,840 KB
testcase_14 AC 1,529 ms
131,856 KB
testcase_15 AC 2,148 ms
175,356 KB
testcase_16 AC 1,412 ms
128,868 KB
testcase_17 AC 1,631 ms
146,360 KB
testcase_18 AC 1,363 ms
124,316 KB
testcase_19 AC 822 ms
83,240 KB
testcase_20 AC 853 ms
83,400 KB
testcase_21 AC 403 ms
48,604 KB
testcase_22 AC 2,599 ms
190,628 KB
testcase_23 AC 2,391 ms
192,788 KB
testcase_24 AC 1,854 ms
151,552 KB
testcase_25 AC 2,268 ms
175,260 KB
testcase_26 AC 1,064 ms
96,464 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def dfs(d,l,r)
  Memo[d][l][r]||=(
    if l==r
      1
    elsif d==0
      if A[l]>=A[r]
        dfs(0,l,r-1)
      else
        [dfs(0,l,r-1),dfs(1,l+1,r)+1].max
      end
    else
      if A[l]<=A[r]
        dfs(1,l+1,r)
      else
        [dfs(1,l+1,r),dfs(0,l,r-1)+1].max
      end
    end
  )
end

N=gets.to_i
A=gets.split.map(&:to_i)
Memo=[0,1].map{(1..N).map{[]}}
p (0...N).flat_map{|i|[dfs(0,i,N-1),dfs(1,0,i)]}.max
0