結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー fastmathfastmath
提出日時 2020-06-26 21:27:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 1,530 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 173,308 KB
実行使用メモリ 20,284 KB
最終ジャッジ日時 2023-09-18 03:00:05
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 9 ms
4,388 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,384 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 267 ms
20,152 KB
testcase_24 AC 274 ms
20,284 KB
testcase_25 AC 277 ms
20,208 KB
testcase_26 AC 271 ms
20,204 KB
testcase_27 AC 279 ms
20,252 KB
testcase_28 AC 190 ms
20,256 KB
testcase_29 AC 190 ms
20,148 KB
testcase_30 AC 212 ms
20,248 KB
testcase_31 AC 215 ms
20,212 KB
testcase_32 AC 209 ms
20,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) 
        cin >> a[i];

    const int INF = 1e18;
    int ans = INF;

    vector <int> l1(n,INF), l2(n,INF), r1(n,INF), r2(n,INF);
    //1 - less

    set <int> ms;
    for (int i = 0; i < n; ++i) {
        ms.insert(a[i]);
        auto t = ms.find(a[i]);
        if (a[i] != *ms.rbegin()) {
            l2[i] = *next(t);
        }
        if (*ms.begin() < a[i]) {
            l1[i] = *ms.begin();
        }   
    }   
    ms.clear();
    for (int i = n - 1; i >= 0; --i) {
        ms.insert(a[i]);
        auto t = ms.find(a[i]);
        if (a[i] != *ms.rbegin()) {
            r2[i] = *next(t);
        }
        if (*ms.begin() < a[i]) {
            r1[i] = *ms.begin();
        }   
    }   

    for (int i = 0; i < n; ++i) {
        //cout << i << ' ' << l2[i] << ' ' << r2[i] << ' ' << a[i] << endl;
        ans = min(ans, l1[i]+r1[i]+a[i]);
        ans = min(ans, l2[i]+r2[i]+a[i]);
    }   

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}
0