結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kk
提出日時 2020-07-15 01:45:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 206,232 KB
実行使用メモリ 13,368 KB
最終ジャッジ日時 2023-08-12 16:20:00
合計ジャッジ時間 9,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge7
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,388 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 9 ms
4,384 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 9 ms
4,384 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 403 ms
13,348 KB
testcase_24 AC 382 ms
12,968 KB
testcase_25 AC 388 ms
13,360 KB
testcase_26 AC 388 ms
13,320 KB
testcase_27 AC 413 ms
13,308 KB
testcase_28 AC 181 ms
13,288 KB
testcase_29 AC 183 ms
13,356 KB
testcase_30 AC 265 ms
13,360 KB
testcase_31 AC 264 ms
13,004 KB
testcase_32 AC 257 ms
13,368 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