CF430B.Balls Game
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color.
For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.
Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.
伊阿胡布正在为国际信息学奥林匹克竞赛(IOI)进行训练。还有什么比玩一款类似“祖玛”(Zuma)的游戏更好的训练方式呢?
有 n 个球排成一行,每个球被染成 k 种颜色中的一种。初始时,该行中不存在三个或更多连续的同色球。伊阿胡布手中有一个颜色为 x 的球。他可以将这个球插入到行中的任意位置(例如,插入在两个球之间)。在任意时刻,只要行中出现三个或更多连续的同色球,它们就会立即被消除。该规则会反复应用,直至行中不再存在三个或更多连续的同色球为止。
例如,若伊阿胡布手中的球序列为 [黑, 黑, 白, 白, 黑, 黑],且他持有一个白色球,则他可将该白球插入两个白球之间。于是三个白球被消除;随后四个黑球变为连续,因此这四个黑球也被全部消除。最终序列中不再剩下任何球,即伊阿胡布成功消除了全部 6 个球。
伊阿胡布希望尽可能多地消除球。现给出球序列的描述以及伊阿胡布所持球的颜色,请帮助他为 IOI 备赛:告诉他最多能从原序列中消除多少个球。
输入格式
The first line of input contains three integers: n (1 ≤ n ≤ 100), k (1 ≤ k ≤ 100) and x (1 ≤ x ≤ k). The next line contains n space-separated integers _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ k). Number c__i means that the i-th ball in the row has color c__i.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
输入的第一行包含三个整数:n(1 ≤ n ≤ 100)、k(1 ≤ k ≤ 100)和 x(1 ≤ x ≤ k)。
第二行包含 n 个用空格分隔的整数 c1,c2,...,cn(1 ≤ ci ≤ k)。其中 ci 表示该行中第 i 个球的颜色为 ci。
保证初始球列中永远不会出现三个或更多颜色相同的连续球。
输出格式
Print a single integer — the maximum number of balls Iahub can destroy.
输出一个整数——Iahub 最多能摧毁的球的数量。
输入输出样例
输入#1
6 2 2 1 1 2 2 1 1
输出#1
6
输入#2
1 1 1 1
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?