結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー milanis48663220milanis48663220
提出日時 2020-06-26 21:36:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 1,849 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 13,784 KB
最終ジャッジ日時 2023-09-18 03:24:21
合計ジャッジ時間 5,531 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 10 ms
4,384 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 396 ms
13,504 KB
testcase_24 AC 413 ms
13,524 KB
testcase_25 AC 400 ms
13,748 KB
testcase_26 AC 384 ms
13,488 KB
testcase_27 AC 378 ms
13,704 KB
testcase_28 AC 178 ms
13,560 KB
testcase_29 AC 174 ms
13,496 KB
testcase_30 AC 253 ms
13,784 KB
testcase_31 AC 258 ms
13,492 KB
testcase_32 AC 254 ms
13,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
int A[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] *= -1;
    }
    int ans = -1e9;
    multiset<int> stl, str;
    stl.insert(A[0]);
    for(int i = 2; i < N; i++) str.insert(A[i]);
    for(int i = 1; i < N-1; i++){
        // < >
        auto l = stl.lower_bound(A[i]);
        auto r = str.lower_bound(A[i]);
        if(l != stl.begin() && r != str.begin()){
            l--; r--;
            if(*l != *r){
                ans = max(ans, *l+*r+A[i]);
            }else{
                if(l != stl.begin()){
                    l--;
                    ans = max(ans, *l+*r+A[i]);
                    l++;
                }
                if(r != stl.begin()){
                    r--;
                    ans = max(ans, *l+*r+A[i]);
                    r++;
                }
            }
        }
        // > <
        l = stl.end(); l--;
        r = str.end(); r--;
        if(*l > A[i] && *r > A[i]){
            if(*l != *r){
                ans = max(ans, *l+*r+A[i]);
            }else{
                if(l != stl.begin()){
                    l--;
                    if(*l > A[i]) ans = max(ans, *l+*r+A[i]);
                    l++;
                }
                if(r != stl.begin()){
                    r--;
                    if(*r > A[i]) ans = max(ans, *l+*r+A[i]);
                    r++;
                }
            }
        }
        stl.insert(A[i]);
        str.erase(str.find(A[i+1]));
    }
    if(ans == -1e9){
        cout << -1 << endl;
    }else{
        cout << -ans << endl;
    }
}
0