結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー chocoruskchocorusk
提出日時 2020-06-27 12:51:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 130,928 KB
実行使用メモリ 6,328 KB
最終ジャッジ日時 2023-09-18 19:18:38
合計ジャッジ時間 3,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9+7;
int solve(int n, vector<int> a){
    int mnl[200020], mnr[200020];
    mnl[0]=INF, mnr[n]=INF;
    for(int i=0; i<n; i++){
        mnl[i+1]=min(mnl[i], a[i]);
    }
    for(int i=n-1; i>=0; i--){
        mnr[i]=min(mnr[i+1], a[i]);
    }
    int ans=INF;
    for(int i=0; i<n; i++){
        if(mnl[i]<a[i] && mnr[i+1]<a[i]) ans=min(ans, a[i]+mnl[i]+mnr[i+1]);
    }
    int t=min_element(a.begin(), a.end())-a.begin();
    ans=min(ans, a[t]+mnl[t]+mnr[t+1]);
    return ans;
}
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    int ans=solve(n, a);
    if(ans>=INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}
0