結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー DenteDente
提出日時 2020-06-26 21:36:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 198,548 KB
実行使用メモリ 7,600 KB
最終ジャッジ日時 2023-09-18 03:25:18
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }
    int lsummn[n + 1], rsummn[n + 1], lsummx[n + 1], rsummx[n + 1];
    lsummn[0] = INF;
    lsummx[0] = -INF;
    rep(i, n) {
        lsummn[i + 1] = min(lsummn[i], a[i]);
        lsummx[i + 1] = max(lsummx[i], a[i]);
    }
    reverse(a, a + n);
    rsummn[0] = INF;
    rsummx[0] = -INF;
    rep(i, n) {
        rsummn[i + 1] = min(rsummn[i], a[i]);
        rsummx[i + 1] = max(rsummx[i], a[i]);
    }
    reverse(a, a + n);
    int ans = INF;
    for (int i = 1; i < n - 1; i++) {
        if (lsummn[i] < a[i] && a[i] > rsummn[n - 1 - i]) {
            ans = min(ans, lsummn[i] + a[i] + rsummn[n - 1 - i]);
        }
        if (lsummx[i] > a[i] && a[i] < rsummx[n - 1 - i]) {
            ans = min(ans, lsummx[i] + a[i] + rsummx[n - 1 - i]);
        }
    }
    cout << (ans != INF ? ans : -1) << endl;
    return 0;
}
0