QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#1822. 山脉回文子数组

统计

如果一个数组先严格递增,然后严格递减,则称其为“山峰状”(Mountainous)数组。注意,山峰状数组的长度必须至少为 3。

“子数组”(Subarray)定义为通过从原数组中删除若干前缀和后缀(可以为空)所得到的数组。

如果一个数组或子数组正向和反向读取的结果相同,则称其为“回文”(Palindrome)数组。

给定一个整数数组,计算既是山峰状又是回文的子数组的最大长度。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^6$),表示数组中整数的个数。 接下来的 $n$ 行,每行包含一个整数 $x$ ($1 \le x \le 10^9$)。这些值按顺序构成了数组。

输出格式

输出一个整数,表示最长的山峰状回文子数组的长度;如果不存在这样的子数组,则输出 $-1$。

样例

样例输入 1

8
2
1
2
3
2
1
7
8

样例输出 1

5

样例输入 2

5
2
5
8
7
2

样例输出 2

-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.