結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-03-05 23:58:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 209,840 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-03-05 23:58:28
合計ジャッジ時間 6,522 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 9 ms
6,676 KB
testcase_14 AC 10 ms
6,676 KB
testcase_15 AC 9 ms
6,676 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 9 ms
6,676 KB
testcase_18 AC 9 ms
6,676 KB
testcase_19 AC 9 ms
6,676 KB
testcase_20 AC 9 ms
6,676 KB
testcase_21 AC 10 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 339 ms
13,568 KB
testcase_24 AC 357 ms
13,568 KB
testcase_25 AC 347 ms
13,568 KB
testcase_26 AC 383 ms
13,568 KB
testcase_27 AC 329 ms
13,568 KB
testcase_28 AC 180 ms
13,568 KB
testcase_29 AC 181 ms
13,568 KB
testcase_30 AC 255 ms
13,568 KB
testcase_31 AC 273 ms
13,568 KB
testcase_32 AC 248 ms
13,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N, ans=2e9, x, y;
    cin >> N;

    vector<int> A(N+1);
    for(int i=1; i<=N; ++i) cin >> A[i];

    set<int> sl, sr;
    for (int i=1; i<=N; ++i) sr.insert(A[i]);

    for (int i=1; i<=N; i++){
        sr.erase(A[i]);
        if (sl.size() == 0 || sr.size() == 0){
            sl.insert(A[i]);
            continue;
        }
        x = *sl.begin();
        y = *sr.begin();
        if (x < A[i] && y < A[i]) ans = min(ans, x+y+A[i]);
        auto xx = sl.lower_bound(A[i]);
        auto yy = sr.lower_bound(A[i]);
        if (xx != sl.end() && yy != sr.end()) ans = min(ans, *xx+*yy+A[i]);
        sl.insert(A[i]);
    }

    if (ans == 2e9) cout << -1;
    else cout << ans;
    cout << '\n';

    return 0;
}
0