結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kappybarkappybar
提出日時 2020-06-26 21:57:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,342 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 171,724 KB
実行使用メモリ 26,020 KB
最終ジャッジ日時 2023-09-18 04:24:34
合計ジャッジ時間 5,795 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 9 ms
4,652 KB
testcase_14 AC 9 ms
4,608 KB
testcase_15 AC 9 ms
4,604 KB
testcase_16 AC 9 ms
4,628 KB
testcase_17 AC 9 ms
4,872 KB
testcase_18 AC 9 ms
4,624 KB
testcase_19 AC 9 ms
4,632 KB
testcase_20 AC 9 ms
4,604 KB
testcase_21 AC 9 ms
4,720 KB
testcase_22 AC 9 ms
4,752 KB
testcase_23 AC 273 ms
26,020 KB
testcase_24 AC 256 ms
25,820 KB
testcase_25 AC 262 ms
25,884 KB
testcase_26 AC 263 ms
25,752 KB
testcase_27 AC 258 ms
25,872 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 222 ms
25,764 KB
testcase_31 AC 222 ms
25,764 KB
testcase_32 AC 218 ms
25,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    scanf("%d",&n);
    vector<int> a(n);
    rep(i,n) scanf("%d",&a[i]);
    vector<int> minl(n),minr(n);
    int mn = INF;
    rep(i,n){
        minl[i] = mn;
        mn = min(mn,a[i]);
    }
    mn = INF;
    for(int i=n-1;i>=0;i--){
        minr[i] = mn;
        mn = min(mn,a[i]);
    }
    int ans = INF;
    rep(i,n){
        if(a[i] > minl[i] && a[i] > minr[i]){
            ans = min(ans,a[i] + minr[i] + minl[i]);
        }
    }
    vector<int> maxr(n,-1),maxl(n,-1);
    set<int> stl;
    rep(i,n){
        auto it = stl.upper_bound(a[i]);
        if(it!=stl.end()) maxl[i] = (*it);
        stl.insert(a[i]);
    }
    set<int> str;
    for(int i=n-1;i>=0;i--){
        auto it = str.upper_bound(a[i]);
        if(it!=str.end()) maxr[i] = (*it);
        str.insert(a[i]);
    }
    rep(i,n){
        if(a[i] < maxl[i] && a[i] < maxr[i]){
            ans = min(ans,a[i] + maxr[i] + maxl[i]);
        }
    }

    if(ans==LINF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0