結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kyoprounokyoprouno
提出日時 2020-06-26 21:58:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 182,172 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2023-09-18 04:28:59
合計ジャッジ時間 5,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 145 ms
13,816 KB
testcase_29 AC 145 ms
13,928 KB
testcase_30 AC 182 ms
13,840 KB
testcase_31 AC 184 ms
14,004 KB
testcase_32 AC 189 ms
13,784 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]);
        }
    }
    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}
0