結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー simansiman
提出日時 2022-09-25 16:17:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 478 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 31,728 KB
最終ジャッジ日時 2023-08-24 00:58:21
合計ジャッジ時間 7,920 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,044 KB
testcase_01 AC 77 ms
15,096 KB
testcase_02 AC 77 ms
15,132 KB
testcase_03 AC 78 ms
15,256 KB
testcase_04 WA -
testcase_05 AC 77 ms
15,148 KB
testcase_06 AC 79 ms
15,264 KB
testcase_07 AC 79 ms
15,136 KB
testcase_08 WA -
testcase_09 AC 76 ms
15,176 KB
testcase_10 WA -
testcase_11 AC 80 ms
15,120 KB
testcase_12 WA -
testcase_13 AC 85 ms
15,708 KB
testcase_14 AC 84 ms
15,768 KB
testcase_15 WA -
testcase_16 AC 87 ms
15,560 KB
testcase_17 WA -
testcase_18 AC 85 ms
15,572 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 86 ms
15,688 KB
testcase_23 AC 221 ms
31,500 KB
testcase_24 AC 221 ms
31,628 KB
testcase_25 AC 218 ms
31,544 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 213 ms
31,636 KB
testcase_29 AC 213 ms
31,560 KB
testcase_30 AC 216 ms
31,672 KB
testcase_31 AC 215 ms
31,624 KB
testcase_32 AC 219 ms
31,504 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:34: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
L = []
R = []

min_v = Float::INFINITY
0.upto(N - 1) do |i|
  a = A[i]
  min_v = a if min_v > a
  L[i] = min_v
end

min_v = Float::INFINITY
(N - 1).downto(0) do |i|
  a = A[i]
  min_v = a if min_v > a
  R[i] = min_v
end

ans = Float::INFINITY

1.upto(N - 2) do |i|
  a = A[i]
  l = L[i - 1]
  r = R[i + 1]
  next if l > a
  next if r > a

  v = a + l + r
  ans = v if ans > v
end

if ans == Float::INFINITY
  puts -1
else
  puts ans
end
0