結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー face4face4
提出日時 2020-07-22 16:49:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 75,016 KB
実行使用メモリ 13,728 KB
最終ジャッジ日時 2023-09-02 22:59:18
合計ジャッジ時間 8,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 11 ms
4,372 KB
testcase_14 AC 11 ms
4,368 KB
testcase_15 AC 11 ms
4,368 KB
testcase_16 AC 11 ms
4,368 KB
testcase_17 AC 11 ms
4,368 KB
testcase_18 AC 11 ms
4,368 KB
testcase_19 AC 11 ms
4,368 KB
testcase_20 AC 11 ms
4,372 KB
testcase_21 AC 11 ms
4,372 KB
testcase_22 AC 11 ms
4,368 KB
testcase_23 AC 471 ms
13,508 KB
testcase_24 AC 476 ms
13,540 KB
testcase_25 AC 464 ms
13,572 KB
testcase_26 AC 476 ms
13,456 KB
testcase_27 AC 465 ms
13,728 KB
testcase_28 AC 232 ms
13,452 KB
testcase_29 AC 228 ms
13,712 KB
testcase_30 AC 316 ms
13,540 KB
testcase_31 AC 317 ms
13,488 KB
testcase_32 AC 309 ms
13,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 1<<30;
    set<int> a, b;
    int v[n];
    for(int i = 0; i < n; i++)  cin >> v[i], (i ? b : a).insert(v[i]);
    for(int i = 1; i+1 < n; i++){
        b.erase(v[i]);
        auto x = a.lower_bound(v[i]);
        auto y = b.lower_bound(v[i]);
        if(x != a.end() && y != b.end()){
            ans = min(ans, v[i]+(*x)+(*y));
        }
        if(*a.begin() < v[i] && *b.begin() < v[i]){
            ans = min(ans, v[i]+*a.begin()+*b.begin());
        }
        a.insert(v[i]);
    }
    cout << (ans==1<<30 ? -1 : ans) << endl;
    return 0;
}
0