結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー SSRSSSRS
提出日時 2020-05-20 08:43:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 168,012 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-05-02 04:53:17
合計ジャッジ時間 3,182 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  //想定WA (場合分けもれ)
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int ans1 = INF;
  vector<int> L1(N);
  L1[0] = A[0];
  for (int i = 1; i < N; i++){
    L1[i] = min(L1[i - 1], A[i]);
  }
  vector<int> R1(N);
  R1[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--){
    R1[i] = min(R1[i + 1], A[i]);
  }
  for (int i = 1; i < N - 1; i++){
    if (L1[i - 1] < A[i] && A[i] > R1[i + 1]){
      ans1 = min(ans1, L1[i - 1] + A[i] + R1[i + 1]);
    }
  }
  if (ans1 == INF){
    cout << -1 << endl;
  } else {
    cout << ans1 << endl;
  }
}
0