結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー sakasu1sakasu1
提出日時 2020-08-12 14:13:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 879 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 163,616 KB
実行使用メモリ 7,512 KB
最終ジャッジ日時 2024-04-18 00:29:05
合計ジャッジ時間 3,386 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 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,944 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 5 ms
6,944 KB
testcase_15 WA -
testcase_16 AC 5 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 5 ms
6,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
6,944 KB
testcase_23 AC 78 ms
7,424 KB
testcase_24 AC 78 ms
7,512 KB
testcase_25 AC 78 ms
7,340 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 78 ms
7,452 KB
testcase_29 AC 77 ms
7,508 KB
testcase_30 AC 79 ms
7,476 KB
testcase_31 AC 74 ms
7,444 KB
testcase_32 AC 75 ms
7,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[200010],i;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    int x[200010],y[200010],z[200010],d[200010];
    x[0]=a[0];
    for(i=1;i<n;i++){
        x[i]=min(x[i-1],a[i]);
    }
    y[i-1]=a[i-1];
    for(i=n-2;i>=0;i--){
        y[i]=min(y[i+1],a[i]);
    }
    z[0]=a[0];
    for(i=1;i<n;i++){
        z[i]=max(z[i-1],a[i]);
    }
    d[i-1]=a[i-1];
    for(i=n-2;i>=0;i--){
        d[i]=min(d[i+1],a[i]);
    }
    int ans=2000000000;
    for(i=1;i<n-1;i++){
        if(a[i]>x[i-1] && a[i]>y[i+1]){
            ans=min(ans,a[i]+x[i-1]+y[i+1]);
        }
    }
    for(i=1;i<n-1;i++){
        if(a[i]<z[i-1] && a[i]<d[i+1]){
            ans=min(ans,a[i]+z[i-1]+d[i+1]);
        }
    }
    if(ans==2000000000){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}
0