結果

問題 No.1188 レベルX門松列
ユーザー tnakao0123tnakao0123
提出日時 2020-08-23 19:04:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 94,424 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 18:19:41
合計ジャッジ時間 1,715 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 13 ms
5,376 KB
testcase_09 AC 2 ms
5,376 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 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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