結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-07-05 11:40:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 169,100 KB
実行使用メモリ 5,756 KB
最終ジャッジ日時 2023-10-22 06:01:31
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int INF = 1e9;


int main()
{
    int n; cin >> n;
    vector<int> a(n), lef(n), rig(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    lef[0] = a[0], rig[n - 1] = a[n - 1];

    for(int i = 1; i < n; i++)lef[i] = min(lef[i - 1], a[i]);
    for(int i = n - 2; i >= 0; i--)rig[i] = min(rig[i + 1], a[i]);


    int nin = INF;

    for(int i = 1; i < n - 1; i++) {
        int l = lef[i - 1], r = rig[i + 1];
        if((l < a[i] && a[i] > r) || (l > a[i] && a[i] < r)) {
            nin = min(nin, l + a[i] + r);
        }
    }
    cout << (nin == INF ? - 1: nin) << endl;
}
0