結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー totori_nyaatotori_nyaa
提出日時 2020-06-26 21:51:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,179 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 200,268 KB
実行使用メモリ 11,440 KB
最終ジャッジ日時 2023-09-18 04:10:21
合計ジャッジ時間 4,067 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 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 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 3 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 3 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 30 ms
11,200 KB
testcase_24 AC 31 ms
11,156 KB
testcase_25 AC 31 ms
11,368 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 30 ms
11,212 KB
testcase_29 AC 31 ms
11,228 KB
testcase_30 AC 30 ms
11,188 KB
testcase_31 AC 30 ms
11,184 KB
testcase_32 AC 30 ms
11,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll lma[n]={}, rma[n]={};
    ll lmi[n]={}, rmi[n]={};
    for(int i=0;i<n;i++){
            lma[i] = a[i];
            lmi[i] = a[i];
            rma[n-1-i] = a[n-1-i];
            rmi[n-1-i] = a[n-1-i];
        if(i){
            chmax(rma[n-1-i], rma[n-i]);
            chmax(lma[i],lma[i-1]);
            chmin(lmi[i],lmi[i-1]);
            chmin(rmi[n-1-i], rmi[n-i]);
        } 
    }
    ll ans = 1e18;
    for(int i=1;i<n-1;i++){
        if(lmi[i]<a[i] && rmi[i] < a[i]) chmin(ans,a[i]+lmi[i]+rmi[i]);
        if(rma[i]>a[i] && lma[i] > a[i]) chmin(ans,rma[i]+a[i]+lma[i]);
    }
    if(ans > 1e9)ans=-1;
    cout << ans << endl;
}
0