結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kyoprounokyoprouno
提出日時 2020-06-26 21:59:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 180,996 KB
実行使用メモリ 13,992 KB
最終ジャッジ日時 2023-09-18 04:31:46
合計ジャッジ時間 8,006 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 461 ms
13,872 KB
testcase_24 AC 466 ms
13,984 KB
testcase_25 AC 471 ms
13,992 KB
testcase_26 AC 448 ms
13,788 KB
testcase_27 AC 447 ms
13,844 KB
testcase_28 AC 194 ms
13,924 KB
testcase_29 AC 198 ms
13,788 KB
testcase_30 AC 294 ms
13,872 KB
testcase_31 AC 300 ms
13,784 KB
testcase_32 AC 294 ms
13,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    set<ll> le,ri;
    rep(i,n){
        cin >> a[i];
        ri.insert(a[i]);
    }
    ll ans=INF;
    rep(i,n){
        if(i==0){
            le.insert(a[i]);
            ri.erase(a[i]);
        }
        if(i==n-1) break;
        ri.erase(a[i]);
        if(*le.rbegin()>a[i] && *ri.rbegin()>a[i]){
            auto v1=le.upper_bound(a[i]);
            auto v2=ri.upper_bound(a[i]);
            ans=min(ans,*v1+*v2+a[i]);
        }
        if(*le.begin()<a[i] && *ri.begin()<a[i]){
            ans=min(ans,*le.begin()+*ri.begin()+a[i]);
        }
        le.insert(a[i]);
    }
    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}
0