結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kk
提出日時 2020-07-15 01:45:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 209,716 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-30 11:10:56
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 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 AC 9 ms
6,944 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 9 ms
6,940 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 9 ms
6,944 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 8 ms
6,940 KB
testcase_23 AC 278 ms
13,440 KB
testcase_24 AC 276 ms
13,440 KB
testcase_25 AC 277 ms
13,440 KB
testcase_26 AC 277 ms
13,312 KB
testcase_27 AC 269 ms
13,440 KB
testcase_28 AC 162 ms
13,440 KB
testcase_29 AC 162 ms
13,440 KB
testcase_30 AC 212 ms
13,440 KB
testcase_31 AC 220 ms
13,312 KB
testcase_32 AC 215 ms
13,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const int INF = 1<<30;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> a(n);
  REP (i, n) cin >> a[i];

  set<int> pref, suff;
  REP (i, n) suff.insert(a[i]);

  int ret = INF;
  REP (i, n) {
    suff.erase(a[i]);

    if (pref.size() && suff.size()) {
      // a[i] is minimum
      auto itr = pref.lower_bound(a[i]);
      auto jtr = suff.lower_bound(a[i]);
      if (itr != pref.end() && jtr != suff.end())
        ret = min(ret, a[i] + *itr + *jtr);

      // a[i] is maximum
      if (a[i] > max(*pref.begin(), *suff.begin()))
        ret = min(ret, a[i] + *pref.begin() + *suff.begin());
    }

    pref.insert(a[i]);
  }

  cout << (ret == INF ? -1 : ret) << endl;
  
  return 0;
}
0