結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー roarisroaris
提出日時 2020-06-27 06:14:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 202,864 KB
実行使用メモリ 14,484 KB
最終ジャッジ日時 2023-09-18 18:57:38
合計ジャッジ時間 6,362 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 337 ms
14,272 KB
testcase_24 AC 333 ms
14,484 KB
testcase_25 AC 332 ms
14,344 KB
testcase_26 AC 322 ms
14,320 KB
testcase_27 AC 344 ms
14,304 KB
testcase_28 AC 179 ms
14,428 KB
testcase_29 AC 178 ms
14,432 KB
testcase_30 AC 246 ms
14,296 KB
testcase_31 AC 247 ms
14,484 KB
testcase_32 AC 245 ms
14,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

int N;
int A[200100];
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    multiset<int> ls, rs;
    ls.insert(A[0]);
    ls.insert(1000000000000);
    for (int i=2; i<N; i++) rs.insert(A[i]);
    rs.insert(1000000000000);
    
    int ans = 1000000000000;
    for (int i=1; i<N-1; i++) {
        int lm = *ls.begin(), rm = *rs.begin();
        if (A[i]>lm && A[i]>rm) ans = min(ans, lm+A[i]+rm);
        int ln = *ls.upper_bound(A[i]), rn = *rs.upper_bound(A[i]);
        ans = min(ans, ln+A[i]+rn);
        ls.insert(A[i]);
        rs.erase(rs.find(A[i+1]));
    }
    if (ans==1000000000000) cout << -1 << endl;
    else cout << ans << endl;
}
0