結果

問題 No.1188 レベルX門松列
ユーザー umezoumezo
提出日時 2020-08-22 16:26:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 198,732 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-23 10:32:59
合計ジャッジ時間 3,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,008 KB
testcase_01 AC 62 ms
9,728 KB
testcase_02 AC 55 ms
9,088 KB
testcase_03 AC 84 ms
11,136 KB
testcase_04 AC 47 ms
11,008 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 23 ms
11,136 KB
testcase_07 AC 47 ms
11,136 KB
testcase_08 AC 48 ms
11,008 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 47 ms
7,936 KB
testcase_15 AC 78 ms
11,136 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 63 ms
9,344 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 59 ms
9,088 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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


int main() {
  ll n;
  cin>>n;
  
  vector<ll> A(n),X(n);
  rep(i,n) cin>>A[i];
  rep(i,n) X[i]=-A[i];
  
  if(n==1 || n==2){
    cout<<0<<endl;
    return 0;
  }
  
  vector<ll> LU(n),LD(n),RU(n),RD(n);
  
  LU[0]=A[0];
  LD[0]=X[0];
  RU[0]=A[n-1];
  RD[0]=X[n-1];
  int lu=1,ld=1,ru=1,rd=1;
  
  vector<ll> B(n),C(n);
  for(int i=1;i<n;i++){
    if(LU[lu-1]<A[i]) LU[lu++]=A[i];
    else *lower_bound(LU.begin(),LU.begin()+lu,A[i])=A[i];
    B[i]=lower_bound(LU.begin(),LU.begin()+lu,A[i])-LU.begin();
  }
  for(int i=1;i<n;i++){
    if(LD[ld-1]<X[i]) LD[ld++]=X[i];
    else *lower_bound(LD.begin(),LD.begin()+ld,X[i])=X[i];
    C[i]=lower_bound(LD.begin(),LD.begin()+ld,X[i])-LD.begin();
  }
  
  vector<ll> E(n),F(n);
  for(int i=n-2;i>=0;i--){
    if(RU[ru-1]<A[i]) RU[ru++]=A[i];
    else *lower_bound(RU.begin(),RU.begin()+ru,A[i])=A[i];
    E[i]=lower_bound(RU.begin(),RU.begin()+ru,A[i])-RU.begin();
  }
  for(int i=n-2;i>=0;i--){
    if(RD[rd-1]<X[i]) RD[rd++]=X[i];
    else *lower_bound(RD.begin(),RD.begin()+rd,X[i])=X[i];
    F[i]=lower_bound(RD.begin(),RD.begin()+rd,X[i])-RD.begin();
  }
  
  ll ma=0;
  for(int i=0;i<n;i++){
    ma=max(ma,max(min(B[i],E[i]),min(C[i],F[i])));
  }
  cout<<ma<<endl;

  return 0;
}
0