CF1138A.Sushi for Two
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ti, where ti=1 means it is with tuna, and ti=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.
阿尔卡季邀请安娜去一家寿司餐厅共进晚餐。这家餐厅有些特别:它提供排成一排的 n 件寿司,顾客必须从中选择一个连续子段来购买。
这些寿司分为两种类型:金枪鱼寿司或鳗鱼寿司。我们用 ti 表示从左往右数第 i 件寿司的类型,其中 ti=1 表示金枪鱼寿司,ti=2 表示鳗鱼寿司。
阿尔卡季不喜欢金枪鱼,安娜不喜欢鳗鱼。因此,阿尔卡季希望选择一个连续子段,使得该子段中两种类型的寿司数量相等,且子段的前半部分全部为同一种类型、后半部分全部为另一种类型(即前后两半各自内部类型均一)。例如,子段 [2,2,2,1,1,1] 是合法的,但子段 [1,2,1,2,1,2] 不合法,因为其前后两半都同时包含两种类型的寿司。
请找出阿尔卡季能购买的最长连续子段的长度。
输入格式
The first line contains a single integer n (2≤n≤100000) — the number of pieces of sushi.
The second line contains n integers t1, t2, ..., tn (ti=1, denoting a sushi with tuna or ti=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.
第一行包含一个整数 n(2≤n≤100000),表示寿司的块数。
第二行包含 n 个整数 t1, t2, ..., tn(其中 ti=1 表示金枪鱼寿司,ti=2 表示鳗鱼寿司),表示从左到右各块寿司的类型。
保证每种类型的寿司至少有一块。注意,这意味着至少存在一个合法的连续子段。
输出格式
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
说明/提示
In the first example Arkady can choose the subsegment [2,2,1,1] or the subsegment [1,1,2,2] with length 4.
In the second example there is no way but to choose one of the subsegments [2,1] or [1,2] with length 2.
In the third example Arkady's best choice is the subsegment [1,1,1,2,2,2].
在第一个例子中,阿尔卡季可以选择长度为 4 的子段 [2,2,1,1] 或子段 [1,1,2,2]。
在第二个例子中,唯一的选择是长度为 2 的子段 [2,1] 或 [1,2]。
在第三个例子中,阿尔卡季的最佳选择是子段 [1,1,1,2,2,2]。
输入解题思路,AI测评打分。不知道怎么写?