結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー CleyLCleyL
提出日時 2022-08-19 00:45:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 76,360 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-16 08:14:22
合計ジャッジ時間 2,919 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 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,940 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 5 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 5 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 84 ms
11,008 KB
testcase_24 AC 84 ms
11,008 KB
testcase_25 AC 85 ms
11,264 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 85 ms
11,008 KB
testcase_29 AC 85 ms
11,008 KB
testcase_30 AC 85 ms
11,008 KB
testcase_31 AC 84 ms
11,136 KB
testcase_32 AC 84 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;cin>>n;
    vector<long long> A(n),lmn(n+1),rmn(n+1),lmx(n+1),rmx(n+1);
    lmn[0] = rmn[0] = 1000000001;
    for(int i = 0; n > i; i++){
        cin>>A[i];
    }
    for(int i = 0; n > i; i++){
        lmn[i+1] = min(lmn[i],A[i]);
        lmx[i+1] = max(lmx[i],A[i]);
        rmn[i+1] = min(rmn[i],A[n-i-1]);
        rmx[i+1] = max(rmx[i],A[n-i-1]);

    }
    long long ans = -1;
    for(int i = 1; n-1 > i; i++){
        if(lmn[i] < A[i] && rmn[n-i-1] < A[i]){
            if(ans == -1)ans = A[i]+lmn[i]+rmn[n-i-1];
            else ans = min(ans,A[i]+lmn[i]+rmn[n-i-1]);
        }
        if(lmx[i] > A[i] && rmx[n-i-1] > A[i]){
            if(ans == -1)ans = A[i]+lmx[i]+rmx[n-i-1];
            else ans = min(ans,A[i]+lmx[i]+rmx[n-i-1]);
        }
    }
    cout << ans << endl;
}

0