結果

問題 No.1188 レベルX門松列
ユーザー simansiman
提出日時 2021-04-30 11:53:09
言語 Ruby
(3.3.0)
結果
AC  
実行時間 847 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 11,564 KB
実行使用メモリ 35,788 KB
最終ジャッジ日時 2023-09-25 12:40:33
合計ジャッジ時間 12,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 837 ms
35,464 KB
testcase_01 AC 661 ms
31,948 KB
testcase_02 AC 601 ms
29,828 KB
testcase_03 AC 804 ms
35,780 KB
testcase_04 AC 805 ms
35,788 KB
testcase_05 AC 80 ms
15,264 KB
testcase_06 AC 847 ms
35,308 KB
testcase_07 AC 806 ms
35,412 KB
testcase_08 AC 805 ms
35,728 KB
testcase_09 AC 80 ms
15,152 KB
testcase_10 AC 81 ms
15,124 KB
testcase_11 AC 126 ms
16,396 KB
testcase_12 AC 132 ms
16,388 KB
testcase_13 AC 133 ms
16,544 KB
testcase_14 AC 485 ms
27,192 KB
testcase_15 AC 794 ms
35,640 KB
testcase_16 AC 88 ms
15,392 KB
testcase_17 AC 622 ms
30,712 KB
testcase_18 AC 82 ms
15,284 KB
testcase_19 AC 590 ms
29,852 KB
testcase_20 AC 81 ms
15,308 KB
testcase_21 AC 83 ms
15,316 KB
testcase_22 AC 81 ms
15,256 KB
testcase_23 AC 82 ms
15,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
B = A.map { |a| -a }

def lis(arr)
  len = arr.size
  dp = Array.new(len, Float::INFINITY)
  h1 = []

  len.times do |i|
    index = dp.bsearch_index { |x| x >= arr[i] }
    dp[index] = arr[i]
    h1.push(index)
  end

  dp2 = Array.new(len, Float::INFINITY)
  arr2 = arr.reverse
  h2 = []

  len.times do |i|
    index = dp2.bsearch_index { |x| x >= arr2[i] }
    dp2[index] = arr2[i]
    h2.unshift(index)
  end

  [*0...len].map { |i| [h1[i], h2[i]].min }.max
end

puts [lis(A), lis(B)].max
0