結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー SSRS
提出日時 2020-05-20 08:45:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 818 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 173,196 KB
実行使用メモリ 24,448 KB
最終ジャッジ日時 2024-11-22 15:43:35
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 14 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  //想定WA2 (場合分けもれ)
  vector<int> L2(N);
  set<int> L;
  for (int i = 0; i < N; i++){
    auto itr = L.upper_bound(A[i]);
    if (itr == L.end()){
      L2[i] = INF;
    } else {
      L2[i] = *itr;
    }
    L.insert(A[i]);
  }
  vector<int> R2(N);
  set<int> R;
  for (int i = N - 1; i >= 0; i--){
    auto itr = R.upper_bound(A[i]);
    if (itr == R.end()){
      R2[i] = INF;
    } else {
      R2[i] = *itr;
    }
    R.insert(A[i]);
  }
  int ans2 = INF;
  for (int i = 1; i < N - 1; i++){
    ans2 = min(ans2, L2[i] + A[i] + R2[i]);
  }
  if (ans2 == INF){
    cout << -1 << endl;
  } else {
    cout << ans2 << endl;
  }
}
0