結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー tempura_pptempura_pp
提出日時 2020-06-26 23:36:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,039 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 120,300 KB
実行使用メモリ 5,492 KB
最終ジャッジ日時 2023-09-18 08:30:58
合計ジャッジ時間 3,667 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 25 ms
5,424 KB
testcase_24 AC 25 ms
5,452 KB
testcase_25 AC 25 ms
5,376 KB
testcase_26 AC 25 ms
5,424 KB
testcase_27 AC 25 ms
5,368 KB
testcase_28 AC 24 ms
5,376 KB
testcase_29 AC 24 ms
5,368 KB
testcase_30 AC 25 ms
5,424 KB
testcase_31 AC 24 ms
5,492 KB
testcase_32 AC 24 ms
5,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n+2);
    rep(i,n)cin>>a[i+1];
    vector<int> l(n+2,inf), r(n+2,inf);
    rep(i,n)l[i+1]=r[i+1]=a[i+1];
    rep(i,n+1)l[i+1]=min(l[i+1],l[i]);
    rep(i,n+1)r[n-i]=min(r[n-i],r[n-i+1]);
    int ans=inf;
    rep(i,n){
        if(l[i]<a[i+1]&&a[i+1]>r[i+2])ans=min(ans,l[i]+a[i+1]+r[i+2]);
        if(l[i]>a[i+1]&&a[i+1]<r[i+2])ans=min(ans,l[i]+a[i+1]+r[i+2]);
    }
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}
0