結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー itohdakitohdak
提出日時 2020-07-03 13:56:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,002 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 14,348 KB
最終ジャッジ日時 2023-10-14 23:30:31
合計ジャッジ時間 5,671 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 9 ms
4,352 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 9 ms
4,352 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 9 ms
4,348 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 306 ms
13,800 KB
testcase_24 AC 324 ms
14,180 KB
testcase_25 AC 306 ms
13,956 KB
testcase_26 AC 300 ms
13,896 KB
testcase_27 AC 315 ms
13,840 KB
testcase_28 AC 176 ms
14,160 KB
testcase_29 AC 173 ms
14,180 KB
testcase_30 AC 236 ms
14,348 KB
testcase_31 AC 233 ms
14,344 KB
testcase_32 AC 233 ms
13,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  set<ll> sel, ser;
  rep(i, N) ser.insert(A[i]);
  ll mn = longinf;
  rep(i, N) {
    ser.erase(A[i]);
    if(!sel.empty() && !ser.empty()) {
      if(*sel.begin() < A[i] && *ser.begin() < A[i]) {
        mn = min(A[i]+*sel.begin()+*ser.begin(), mn);
      }
      auto itrl = sel.lower_bound(A[i]+1);
      auto itrr = ser.lower_bound(A[i]+1);
      if(itrl != sel.end() && itrr != ser.end()) {
        mn = min(A[i]+*itrl+*itrr, mn);
      }
    }
    sel.insert(A[i]);
  }
  cout << (mn==longinf ? -1 : mn) << "\n";
  return 0;
}
0