結果

問題 No.1188 レベルX門松列
ユーザー kens
提出日時 2020-08-22 16:03:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 195,212 KB
最終ジャッジ日時 2025-01-13 09:57:10
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

vector<int> LIS(vector<int> &a) {
  const int INF = 2e9;
  int l = a.size();
  vector<int> dp(l,INF), v(l);
  rep(i,l) {
    v[i] = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin();
    *lower_bound(dp.begin(),dp.end(),a[i]) = a[i];
  }
  return v;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n), d(n);
  rep(i,n) {
    cin >> a[i];
    b[n-1-i] = a[i];
    c[i] = -a[i];
    d[n-1-i] = -a[i];
  }
  vector<int> va = LIS(a);
  vector<int> vb = LIS(b);
  vector<int> vc = LIS(c);
  vector<int> vd = LIS(d);
  int ans = 0;
  for(int i = 1; i < n-1; i++) {
    ans = max(ans,min(va[i],vb[n-i-1]));
    ans = max(ans,min(vc[i],vd[n-i-1]));
  }
  cout << ans << endl;
  return 0;
}
0