結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー itohdakitohdak
提出日時 2020-07-03 13:52:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 938 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 174,016 KB
実行使用メモリ 14,188 KB
最終ジャッジ日時 2023-10-14 23:30:19
合計ジャッジ時間 5,181 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,352 KB
testcase_12 WA -
testcase_13 AC 8 ms
4,352 KB
testcase_14 AC 8 ms
4,352 KB
testcase_15 WA -
testcase_16 AC 7 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 7 ms
4,352 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 8 ms
4,352 KB
testcase_23 AC 240 ms
13,948 KB
testcase_24 AC 238 ms
14,188 KB
testcase_25 AC 248 ms
13,808 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 143 ms
13,808 KB
testcase_29 AC 149 ms
13,868 KB
testcase_30 AC 189 ms
13,948 KB
testcase_31 AC 190 ms
14,172 KB
testcase_32 AC 188 ms
14,172 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);
      }
      if(*sel.rbegin() > A[i] && *ser.rbegin() > A[i]) {
        mn = min(A[i]+*sel.rbegin()+*ser.rbegin(), mn);
      }
    }
    sel.insert(A[i]);
  }
  cout << (mn==longinf ? -1 : mn) << "\n";
  return 0;
}
0