結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー QDSNQDSN
提出日時 2020-07-04 21:35:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 175,832 KB
実行使用メモリ 14,192 KB
最終ジャッジ日時 2023-10-19 16:10:19
合計ジャッジ時間 8,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 12 ms
4,348 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 12 ms
4,348 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 12 ms
4,348 KB
testcase_19 AC 12 ms
4,348 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 448 ms
14,192 KB
testcase_24 AC 475 ms
14,192 KB
testcase_25 AC 468 ms
14,192 KB
testcase_26 AC 457 ms
14,192 KB
testcase_27 AC 484 ms
14,192 KB
testcase_28 AC 233 ms
14,192 KB
testcase_29 AC 234 ms
14,192 KB
testcase_30 AC 320 ms
14,192 KB
testcase_31 AC 331 ms
14,192 KB
testcase_32 AC 323 ms
14,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    set<ll> stl, str;
    for(int i = 1; i < n; i++) {
        str.insert(a[i]);
    }
    ll ans = LLONG_MAX;
    for(int i = 1; i < n - 1; i++) {
        stl.insert(a[i - 1]);
        str.erase(a[i]);
        auto x = stl.lower_bound(a[i]);
        auto y = str.lower_bound(a[i]);
        if(x != stl.end() && y != str.end()) {
            ans = min(ans, (*x) + (*y) + a[i]);
        }
        auto v = *stl.begin();
        auto w = *str.begin();
        if(v < a[i] && w < a[i]) {
            ans = min(ans, v + w + a[i]);
        }
    }
    if(ans < MOD) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}
0