結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー | siman |
提出日時 | 2022-09-25 16:32:18 |
言語 | Ruby (3.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 935 bytes |
コンパイル時間 | 276 ms |
コンパイル使用メモリ | 11,284 KB |
実行使用メモリ | 41,752 KB |
最終ジャッジ日時 | 2023-08-24 00:59:02 |
合計ジャッジ時間 | 6,754 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
19,640 KB |
testcase_01 | AC | 81 ms
15,108 KB |
testcase_02 | AC | 81 ms
15,292 KB |
testcase_03 | AC | 80 ms
15,136 KB |
testcase_04 | AC | 81 ms
15,144 KB |
testcase_05 | AC | 82 ms
15,236 KB |
testcase_06 | AC | 82 ms
15,112 KB |
testcase_07 | AC | 81 ms
15,148 KB |
testcase_08 | AC | 80 ms
15,132 KB |
testcase_09 | AC | 81 ms
15,040 KB |
testcase_10 | AC | 81 ms
15,224 KB |
testcase_11 | AC | 82 ms
15,276 KB |
testcase_12 | AC | 81 ms
15,044 KB |
testcase_13 | AC | 116 ms
15,900 KB |
testcase_14 | AC | 115 ms
15,816 KB |
testcase_15 | AC | 116 ms
16,060 KB |
testcase_16 | AC | 115 ms
16,004 KB |
testcase_17 | AC | 118 ms
15,800 KB |
testcase_18 | AC | 115 ms
15,832 KB |
testcase_19 | AC | 116 ms
15,824 KB |
testcase_20 | AC | 116 ms
15,832 KB |
testcase_21 | AC | 117 ms
15,896 KB |
testcase_22 | AC | 117 ms
15,932 KB |
testcase_23 | TLE | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
コンパイルメッセージ
Main.rb:67: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N = gets.to_i A = gets.split.map(&:to_i) L = [] R = [] LA = [] RA = [] LL = Array.new(N, -1) RR = Array.new(N, -1) min_v = Float::INFINITY 0.upto(N - 1) do |i| a = A[i] idx = LA.bsearch_index { |x| x > a } || LA.size if idx < LA.size LL[i] = a + LA[idx] end LA.insert(idx, a) if min_v > a min_v = a end L[i] = min_v end min_v = Float::INFINITY (N - 1).downto(0) do |i| a = A[i] idx = RA.bsearch_index { |x| x > a } || RA.size if idx < RA.size RR[i] = a + RA[idx] end RA.insert(idx, a) if min_v > a min_v = a end R[i] = min_v end ans = Float::INFINITY 1.upto(N - 2) do |i| a = A[i] l = LL[i] r = RR[i] next if l == -1 next if r == -1 v = l + r - a ans = v if ans > v end 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