結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー bonKotsubonKotsu
提出日時 2021-05-31 14:56:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 167,272 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-26 08:05:17
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,812 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 1 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 WA -
testcase_16 AC 5 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 5 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 87 ms
11,136 KB
testcase_24 AC 83 ms
11,008 KB
testcase_25 AC 82 ms
11,264 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 83 ms
11,136 KB
testcase_29 AC 84 ms
11,264 KB
testcase_30 AC 84 ms
11,008 KB
testcase_31 AC 85 ms
11,136 KB
testcase_32 AC 81 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

const ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> mxl(n), mxr(n), mnl(n, INF), mnr(n, INF);
  for (int i = 1; i < n; i++) {
    mnl[i] = min(mnl[i-1], a[i-1]);
    mxl[i] = max(mxl[i-1], a[i-1]);
  }
  for (int i = n-2; i >= 0; i--) {
    mnr[i] = min(mnr[i+1], a[i+1]);
    mxr[i] = max(mxr[i+1], a[i+1]);
  }

  ll ans = INF;
  for (int i = 1; i < n-1; i++) {
    if (a[i] > mnl[i] && a[i] > mnr[i]) {
      ans = min(ans, a[i]+mnl[i]+mnr[i]);
    }
    if (a[i] < mxl[i] && a[i] < mxr[i]) {
      ans = min(ans, a[i]+mxl[i]+mxr[i]);
    }
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;


}
0