A9560 | Balls Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.
输出格式
Print a single integer — the maximum number of balls Iahub can destroy.
输入输出样例
输入 #1
6 2 2 1 1 2 2 1 1
输出 #1
6
输入 #2
1 1 1 1
输出 #2
0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted