結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー DenteDente
提出日時 2020-06-26 21:59:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 204,676 KB
実行使用メモリ 13,768 KB
最終ジャッジ日時 2023-09-18 04:32:09
合計ジャッジ時間 8,053 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 490 ms
13,516 KB
testcase_24 AC 507 ms
13,548 KB
testcase_25 AC 503 ms
13,504 KB
testcase_26 AC 488 ms
13,528 KB
testcase_27 AC 477 ms
13,656 KB
testcase_28 AC 232 ms
13,504 KB
testcase_29 AC 230 ms
13,548 KB
testcase_30 AC 323 ms
13,520 KB
testcase_31 AC 334 ms
13,768 KB
testcase_32 AC 329 ms
13,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    set<int> L, R;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        if (i) R.emplace(a[i]);
    }
    L.emplace(a[0]);
    int ans = INF;
    for (int i = 1; i < n - 1; i++) {
        auto litr = L.upper_bound(a[i]);
        auto ritr = R.upper_bound(a[i]);
        if(litr != L.end() && ritr != R.end()){
            ans = min(ans, *litr + a[i] + *ritr);
        }
        if(*L.begin() < a[i] && a[i] > *R.begin()){
            ans = min(ans, *L.begin() + a[i] + *R.begin());
        }
        L.emplace(a[i]);
        R.erase(a[i]);
    }
    cout << (ans != INF ? ans : -1) << endl;
    return 0;
}
0