結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー kappybarkappybar
提出日時 2020-06-26 21:28:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 166,964 KB
実行使用メモリ 7,248 KB
最終ジャッジ日時 2023-09-18 03:03:41
合計ジャッジ時間 3,807 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 4 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 4 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 72 ms
7,012 KB
testcase_24 AC 72 ms
7,168 KB
testcase_25 AC 73 ms
7,064 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 71 ms
7,068 KB
testcase_29 AC 72 ms
6,952 KB
testcase_30 AC 72 ms
6,964 KB
testcase_31 AC 72 ms
7,064 KB
testcase_32 AC 72 ms
6,952 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;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> minr(n),maxr(n);
    vector<int> minl(n),maxl(n);
    int mn = INF,mx = -1;
    rep(i,n){
        minr[i] = mn;
        maxr[i] = mx;
        mn = min(mn,a[i]);
        mx = max(mx,a[i]);
    }
    mn = INF,mx = -1;
    for(int i=n-1;i>=0;i--){
        minl[i] = mn;
        maxl[i] = mx;
        mn = min(mn,a[i]);
        mx = max(mx,a[i]);
    }
    ll ans = LINF;
    for(int i=1;i<n-1;i++){
        ll res = a[i];
        if(minr[i] < a[i] && minl[i] < a[i]){
            ans = min(ans,res + minr[i] + minl[i]);
        }
        if(maxr[i] > a[i] && maxl[i] > a[i]){
            ans = min(ans,res + maxr[i] + maxl[i]);
        }
    }
    if(ans==LINF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0