結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー ぷらぷら
提出日時 2021-03-15 17:30:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 169,632 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-24 20:02:37
合計ジャッジ時間 6,644 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 10 ms
5,376 KB
testcase_22 AC 10 ms
5,376 KB
testcase_23 AC 320 ms
13,312 KB
testcase_24 AC 313 ms
13,568 KB
testcase_25 AC 326 ms
13,440 KB
testcase_26 AC 328 ms
13,440 KB
testcase_27 AC 325 ms
13,440 KB
testcase_28 AC 211 ms
13,312 KB
testcase_29 AC 209 ms
13,312 KB
testcase_30 AC 270 ms
13,312 KB
testcase_31 AC 267 ms
13,440 KB
testcase_32 AC 271 ms
13,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    set<int>l,r;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        r.insert(A[i]);
    }
    int ans = 1e9;
    for(int i = 0; i < N; i++) {
        r.erase(A[i]);
        if(l.size() && r.size()) {
            if(*l.begin() < A[i] && *r.begin() < A[i]) {
                ans = min(ans,A[i]+*l.begin()+*r.begin());
            }
            auto it1 = l.lower_bound(A[i]);
            auto it2 = r.lower_bound(A[i]);
            if(it1 != l.end() && it2 != r.end()) {
                ans = min(ans,A[i]+*it1+*it2);
            }
        }
        l.insert(A[i]);
    }
    if(ans == 1e9) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}
0