結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,384 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 4 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 5 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 72 ms
7,436 KB
testcase_24 AC 72 ms
7,372 KB
testcase_25 AC 72 ms
7,288 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 72 ms
7,340 KB
testcase_29 AC 72 ms
7,220 KB
testcase_30 AC 72 ms
7,304 KB
testcase_31 AC 72 ms
7,300 KB
testcase_32 AC 73 ms
7,288 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];
    fill(lsummn, lsummn + n + 1, INF);
    fill(lsummx, lsummx + n + 1, -INF);
    rep(i, n) {
        lsummn[i + 1] = min(lsummn[i], a[i]);
        lsummx[i + 1] = max(lsummx[i], a[i]);
    }
    reverse(a, a + n);
    fill(rsummn, rsummn + n + 1, INF);
    fill(rsummx, rsummx + n + 1, -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