結果

問題 No.1188 レベルX門松列
ユーザー umezoumezo
提出日時 2020-08-22 14:59:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 995 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 199,372 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 09:23:06
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 17 ms
6,944 KB
testcase_07 AC 28 ms
6,940 KB
testcase_08 AC 29 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 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);
  rep(i,n) cin>>A[i];
  
  if(n==1 || n==2){
    cout<<0<<endl;
    return 0;
  }
  
  vector<ll> B;
  int x=0,cnt=0;
  if(A[0]<A[1]){
    x=1;
    cnt=1;
  }
  else if(A[0]>A[1]){
    x=-1;
    cnt=1;
  }
  
  for(int i=2;i<=n;i++){
    if(x==1 && A[i-1]<A[i]) cnt++;
    else if((x==1 || x==-1) && A[i-1]==A[i]){
      B.push_back(cnt);
      x=0;
      cnt=0;
    }
    else if(x==-1 && A[i-1]>A[i]) cnt++;
    else if(A[i-1]<A[i]){
      B.push_back(cnt);
      cnt=1;
      x=1;
    }
    else if(A[i-1]>A[i]){
      B.push_back(cnt);
      cnt=1;
      x=-1;
    }
    B.push_back(cnt);
  }
  
  int ma=0;
  int k=B.size();
  if(k<2) cout<<0<<endl;
  else{
    for(int i=0;i<k-1;i++){
      int t=min(B[i],B[i+1]);
      ma=max(ma,t);
    }
    cout<<ma<<endl;
  }

  return 0;
}
0