306046: CF1138A. Sushi for Two
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Sushi for Two
题意翻译
**题意:** 给一长度为$n$的序列$\{t\}$,并保证$t_i=1$或$2$. 一子串合法当且仅当:(设其长度为$k$,$k$偶数) $[1,\frac{k}{2}]$部分的子串只包含一种数,$[\frac{k}{2}+1,k]$部分的子串只包含一种数,而且两部分数不同。例如$[2,2,2,1,1,1]$是合法的,$[1,2,1,2,1,2]$不合法。 请寻找一最长的合法子串。 **输入:** 第一行一整数$2\le n\le 100000$,第二行$n$个整数描述序列。 **输出:** 一个整数表示最长合法子串长度。 **样例1解释:** $[2,2,1,1]$和$[1,1,2,2]$都是合法的最长子串。故ans=4.题目描述
Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $ n $ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the $ i $ -th from the left sushi as $ t_i $ , where $ t_i = 1 $ means it is with tuna, and $ t_i = 2 $ means it is with eel. Arkady does not like tuna, Anna does not like eel. Arkady wants to choose such a continuous subsegment of sushi that it has equal number of sushi of each type and each half of the subsegment has only sushi of one type. For example, subsegment $ [2, 2, 2, 1, 1, 1] $ is valid, but subsegment $ [1, 2, 1, 2, 1, 2] $ is not, because both halves contain both types of sushi. Find the length of the longest continuous subsegment of sushi Arkady can buy.输入输出格式
输入格式
The first line contains a single integer $ n $ ( $ 2 \le n \le 100\,000 $ ) — the number of pieces of sushi. The second line contains $ n $ integers $ t_1 $ , $ t_2 $ , ..., $ t_n $ ( $ t_i = 1 $ , denoting a sushi with tuna or $ t_i = 2 $ , denoting a sushi with eel), representing the types of sushi from left to right. It is guaranteed that there is at least one piece of sushi of each type. Note that it means that there is at least one valid continuous segment.
输出格式
Print a single integer — the maximum length of a valid continuous segment.
输入输出样例
输入样例 #1
7
2 2 2 1 1 2 2
输出样例 #1
4
输入样例 #2
6
1 2 1 2 1 2
输出样例 #2
2
输入样例 #3
9
2 2 1 1 1 2 2 2 2
输出样例 #3
6