結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー mikianaaamikianaaa
提出日時 2020-08-19 19:39:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,355 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 173,064 KB
実行使用メモリ 785,920 KB
最終ジャッジ日時 2024-04-20 09:49:36
合計ジャッジ時間 5,606 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<ll> lmin(N), rmin(N);
    ll lmi = INF, rmi = INF;
    rep(i, N) {
        lmi = min(lmi, A[i]);
        lmin[i] = lmi;
    }

    for (int i = N - 1; i > -1; i--) {
        rmi = min(rmi, A[i]);
        rmin[i] = rmi;
    }

    vector<set<ll>> lse(N), rse(N);
    set<ll> sel, ser;
    sel.insert(INF), ser.insert(INF);
    rep(i, N) {
        sel.insert(A[i]);
        lse[i] = sel;
    }

    for (int i = N - 1; i > -1; i--) {
        ser.insert(A[i]);
        rse[i] = ser;
    }

    ll atype = INF, btype = INF;
    for (int i = 1; i < N - 1; i++) {
        if (A[i] > rmin[i + 1] && A[i] > lmin[i - 1])
            atype = min(atype, A[i] + rmin[i + 1] + lmin[i - 1]);
    }

    for (int i = 1; i < N - 1; i++) {
        ll a = *lse[i - 1].upper_bound(A[i]);
        ll b = *rse[i + 1].upper_bound(A[i]);
        btype = min(btype, a + A[i] + b);
    }

    ll ans = min(atype, btype);
    cout << (ans == INF ? -1 : ans) << endl;
}
0