結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-07-16 10:58:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,470 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 108,240 KB
実行使用メモリ 17,384 KB
最終ジャッジ日時 2024-05-03 09:09:48
合計ジャッジ時間 6,080 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 12 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 11 ms
6,944 KB
testcase_17 WA -
testcase_18 AC 12 ms
6,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 12 ms
6,944 KB
testcase_23 AC 382 ms
17,280 KB
testcase_24 AC 372 ms
17,252 KB
testcase_25 AC 365 ms
17,256 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 227 ms
17,280 KB
testcase_29 AC 226 ms
17,256 KB
testcase_30 AC 297 ms
17,256 KB
testcase_31 AC 292 ms
17,248 KB
testcase_32 AC 298 ms
17,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9; 

ll maxl[200010];
ll maxr[200010];

int main(void){
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    maxl[0]=0;
    for(int i=0;i<n;i++){
        maxl[i+1]=max(maxl[i],a[i]);
    }
    reverse(a.begin(),a.end());
    for(int i=0;i<n;i++){
        maxr[i+1]=max(maxr[i],a[i]);
    }
    reverse(a.begin(),a.end());
    set<ll>s1,s2;
    s1.insert(a[0]);
    for(int i=1;i<n;i++)s2.insert(a[i]);
    ll ans = (ll)INF;
    for(int i=1;i<n;i++){
        ll l = maxl[i];
        ll r = maxr[n-1-i];
        if((l>a[i])&&(a[i]<r)){
            ans = min(ans,l+r+a[i]);
        }
        s2.erase(a[i]);
        auto itr1 = s1.lower_bound(a[i]);
        auto itr2 = s2.lower_bound(a[i]);
        if(itr1==s1.begin()){
            s1.insert(a[i]);
            continue;
        }
        if(itr2==s2.begin()){
            s1.insert(a[i]);
            continue;
        }
        ans = min(ans,a[i]+*(s1.begin())+*(s2.begin()));
        s1.insert(a[i]);
    }
    if(ans == (ll)INF)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}
0