CF909D.Colorful Points

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.

You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.

How many operations will you need to perform until the next operation does not have any points to delete?

给你一条直线上的若干个点,每个点都被赋予了一种颜色。对于点 aa,它的邻居是指那些与 aa 之间不存在其他点的点。每个点至多有两个邻居——一个在左侧,一个在右侧。

你将对这组点执行一系列操作。每次操作中,你将删除所有与其至少一个邻居颜色不同的点。这些点是同时删除的,即:首先确定所有需要被删除的点,然后一次性全部删除。之后你可以继续执行下一次操作,依此类推。如果某次操作不会删除任何点,则不允许执行该操作。

问:你需要执行多少次操作,才能使得下一次操作不再有任何点可删除?

输入格式

Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.

The number of the points is between 1 and 106.

输入包含一个仅由小写英文字母 'a'–'z' 组成的字符串。这些字母按点在直线上的排列顺序给出各点的颜色:第一个字母表示最左侧点的颜色,第二个字母表示从左往右数第二个点的颜色,依此类推。

点的总数在 11 到 10610^6 之间。

输出格式

Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

输出一行,包含一个整数——对给定的点集执行操作(删除点)直至无法再删除任何点时,所能执行的操作次数。

输入输出样例

  • 输入#1

    aabb

    输出#1

    2
  • 输入#2

    aabcaa

    输出#2

    1

说明/提示

In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.

In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.

在第一个测试用例中,第一次操作将删除两个中间点,剩下点“ab”,这两个点将在第二次操作中被删除。此时已无剩余点可进行第三次操作。

在第二个测试用例中,第一次操作将删除中间的四个点,剩下点“aa”。它们均无其他颜色的相邻点,因此无法执行第二次操作。

输入解题思路,AI测评打分。不知道怎么写?

首页