結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー bonKotsubonKotsu
提出日時 2021-05-31 15:17:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 170,196 KB
実行使用メモリ 14,880 KB
最終ジャッジ日時 2024-04-26 08:06:37
合計ジャッジ時間 31,244 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> mxl(n), mxr(n), mnl(n, INF), mnr(n, INF);

  set<int> sl, sr;
  for (int i = 1; i < n; i++) {
    mnl[i] = min(mnl[i-1], a[i-1]);
    sl.insert(a[i-1]);
    auto it = upper_bound(sl.begin(), sl.end(), a[i]);
    if (it == sl.end()) mxl[i] = INF;
    else mxl[i] = *it;
  }
  for (int i = n-2; i >= 0; i--) {
    mnr[i] = min(mnr[i+1], a[i+1]);
    sr.insert(a[i+1]);
    auto it = upper_bound(sr.begin(), sr.end(), a[i]);
    if (it == sr.end()) mxr[i] = INF;
    else mxr[i] = *it;
  }


  int ans = INF;
  for (int i = 1; i < n-1; i++) {
    if (a[i] > mnl[i] && a[i] > mnr[i]) {
      ans = min(ans, a[i]+mnl[i]+mnr[i]);
    }
    if (a[i] < mxl[i] && a[i] < mxr[i]) {
      ans = min(ans, a[i]+mxl[i]+mxr[i]);
    }
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;


}
0