結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー CleyLCleyL
提出日時 2022-08-19 00:44:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 76,368 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-16 08:13:16
合計ジャッジ時間 3,419 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,940 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 2 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,944 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,944 KB
testcase_23 AC 82 ms
7,168 KB
testcase_24 AC 82 ms
7,168 KB
testcase_25 AC 82 ms
7,040 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 83 ms
7,168 KB
testcase_29 AC 82 ms
7,168 KB
testcase_30 AC 83 ms
7,168 KB
testcase_31 AC 82 ms
7,296 KB
testcase_32 AC 81 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> 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]);

    }
    int 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