結果

問題 No.1188 レベルX門松列
ユーザー tnakao0123
提出日時 2020-08-23 19:04:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 95,048 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-15 19:02:02
合計ジャッジ時間 1,790 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1188.cc:  No.1188 レベルX門松列 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N], q0[MAX_N], q1[MAX_N];
int dp0[MAX_N], dp1[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int qt0 = 0, qt1 = 0;
  for (int i = 0; i < n; i++) {
    while (qt0 > 0 && as[q0[qt0 - 1]] <= as[i]) qt0--;
    while (qt1 > 0 && as[q1[qt1 - 1]] >= as[i]) qt1--;
    q0[qt0++] = q1[qt1++] = i;
    dp0[i] = qt0, dp1[i] = qt1;
  }

  qt0 = qt1 = 0;
  int maxl = 0;
  for (int i = 0; i < n; i++) {
    while (qt0 > 0 && as[q0[qt0 - 1]] <= as[i]) qt0--;
    while (qt1 > 0 && as[q1[qt1 - 1]] >= as[i]) qt1--;
    q0[qt0++] = q1[qt1++] = i;

    int l = max(min(dp0[i], qt0), min(dp1[i], qt1)) - 1;
    if (maxl < l) maxl = l;
  }

  printf("%d\n", maxl);
  return 0;
}
0