問題一覧 > 通常問題

No.1188 Level X Kadomatsu Sequence

レベル : / AI推定難易度 : 1150 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 141
作問者 : seven_three / テスター : Thistle
お気に入りにしたユーザー ProblemId : 4880 / 自分の提出
問題文最終更新日: 2020-08-22 10:50:20
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
技術室奥プログラミングコンテスト#5 Day1 (順位表) の他の問題:

Problem Statement

We define a Kadomatsu sequence and its level as follows.

・ A Kadomatsu sequence of level $X$ is a sequence consisting of $2X+1$ elements.
・ When its elements are denoted by $B_{1},B_{2},...B_{2X+1}$,
 $B_{1}$ $>$ $B_{2}$ $>$ ... $B_{X}$ $>$ $B_{X+1}$ $<$ $B_{X+2}$ ... $<$ $B_{2X}$ $<$ $B_{2X+1}$ or $B_{1}$ $<$ $B_{2}$ $<$ ... $B_{X}$ $<$ $B_{X+1}$ $>$ $B_{X+2}$ ... $>$ $B_{2X}$ $>$ $B_{2X+1}$

You are given a sequence $A_{1},A_{2},...A_{N}$ consisting of $N$ elements.
Among the subsequences of this sequence that are Kadomatsu sequences, find the level of the one with the highest level.
Here, a subsequence of a sequence is the sequence obtained by choosing and deleting 0 or more elements of the sequence and arranging the remaining elements in their original order.

Input

$N$
$A_{1}\ A_{2}\ ...\ A_{N}$

$1$ $≤$ $N$ $≤$ $10^5$
$1$ $≤$ $A_{i}$ $≤$ $10^9$ $(1≤i≤N)$
All inputs are integers.

Output

Print a newline at the end.

Sample

Sample 1
Input
3
1 3 2
Output
1

The highest-level Kadomatsu sequence that is a subsequence of the sequence $A$ is $\{1,3,2\}$, and its level is $1$.

Sample 2
Input
1
1
Output
0

The highest-level Kadomatsu sequence that is a subsequence of the sequence $A$ is $\{1\}$, and its level is $0$.

Sample 3
Input
6
5 3 1 2 4 2
Output
2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。