結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー IKyoproIKyopro
提出日時 2020-06-26 21:51:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 206,800 KB
実行使用メモリ 14,300 KB
最終ジャッジ日時 2023-09-18 04:11:39
合計ジャッジ時間 6,953 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 404 ms
13,844 KB
testcase_24 AC 395 ms
13,936 KB
testcase_25 AC 383 ms
13,804 KB
testcase_26 AC 384 ms
13,808 KB
testcase_27 AC 404 ms
13,840 KB
testcase_28 AC 193 ms
13,876 KB
testcase_29 AC 193 ms
14,152 KB
testcase_30 AC 267 ms
13,840 KB
testcase_31 AC 272 ms
13,936 KB
testcase_32 AC 267 ms
14,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    ll inf = 1e18;
    ll ans = inf;
    set<ll> L,R;
    for(int i=0;i<N;i++){
        cin >> A[i];
        R.insert(A[i]);
    }
    L.insert(A[0]);
    R.erase(A[0]);
    for(int i=1;i<N-1;i++){
        R.erase(A[i]);
        ll ml = *L.begin(),mr = *R.begin();
        if(A[i]>ml && A[i]>mr) ans = min(ans,A[i]+ml+mr);
        bool ok = true;
        auto itl = L.lower_bound(A[i]);
        ok &= itl!=L.end();
        auto itr = R.lower_bound(A[i]);
        ok &= itr!=R.end();
        if(ok){
//            cerr << i << *itl << " " << *itr << "\n";
            ans = min(ans,A[i]+*itl+*itr);
        }
        L.insert(A[i]);
    }
    cout << (ans!=inf? ans:-1) << "\n";
}
0