結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー milanis48663220milanis48663220
提出日時 2020-06-26 21:35:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,889 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-18 03:20:12
合計ジャッジ時間 32,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 = lower_bound(stl.begin(), stl.end(), A[i]);
        auto r = lower_bound(str.begin(), str.end(), 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