CF926C.Is This a Zebra?

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means that the corresponding column is black.

You think that this photo can contain a zebra. In this case the whole photo should consist of several (possibly, only one) alternating black and white stripes of equal width. For example, the photo [0, 0, 0, 1, 1, 1, 0, 0, 0] can be a photo of zebra, while the photo [0, 0, 0, 1, 1, 1, 1] can not, because the width of the black stripe is 3, while the width of the white stripe is 4. Can the given photo be a photo of zebra or not?

你偶然遗留在沙漠中的一台相机拍摄了一张有趣的照片。该照片的宽度分辨率为 nn 像素,且照片的每一列均为全白或全黑。因此,我们可以将这张照片表示为一个由 nn 个 0 和 1 组成的序列,其中 0 表示对应列全白,1 表示对应列全黑。

你认为这张照片可能拍到了一头斑马。此时,整张照片应由若干(可能仅一个)宽度相等、黑白交替的条纹组成。例如,照片 [0, 0, 0, 1, 1, 1, 0, 0, 0][0, 0, 0, 1, 1, 1, 0, 0, 0] 可能是一张斑马照片;而照片 [0, 0, 0, 1, 1, 1, 1][0, 0, 0, 1, 1, 1, 1] 则不可能,因为黑色条纹的宽度为 3,而白色条纹的宽度为 4。给定的照片能否是一张斑马照片?

输入格式

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the width of the photo.

The second line contains a sequence of integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 1) — the description of the photo. If a__i is zero, the i-th column is all black. If a__i is one, then the i-th column is all white.

第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)——照片的宽度。

第二行包含一个整数序列 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(0≤ai≤10 \leq a_i \leq 1)——照片的描述。若 aia_i 为 0,则第 ii 列全为黑色;若 aia_i 为 1,则第 ii 列全为白色。

输出格式

If the photo can be a photo of zebra, print "YES" (without quotes). Otherwise, print "NO".

You can print each letter in any case (upper or lower).

如果该照片可能是斑马的照片,则输出 “YES”(不带引号);否则输出 “NO”。

你可以以任意大小写形式输出每个字母(大写或小写)。

输入输出样例

  • 输入#1

    9
    0 0 0 1 1 1 0 0 0

    输出#1

    YES
  • 输入#2

    7
    0 0 0 1 1 1 1

    输出#2

    NO
  • 输入#3

    5
    1 1 1 1 1

    输出#3

    YES
  • 输入#4

    8
    1 1 1 0 0 0 1 1

    输出#4

    NO
  • 输入#5

    9
    1 1 0 1 1 0 1 1 0

    输出#5

    NO

说明/提示

The first two examples are described in the statements.

In the third example all pixels are white, so the photo can be a photo of zebra.

In the fourth example the width of the first stripe is equal to three (white color), the width of the second stripe is equal to three (black), and the width of the third stripe is equal to two (white). Thus, not all stripes have equal length, so this photo is not a photo of zebra.

前两个示例已在题目描述中给出。

在第三个示例中,所有像素均为白色,因此该照片可以是一张斑马的照片。

在第四个示例中,第一条条纹的宽度为三(白色),第二条条纹的宽度为三(黑色),第三条条纹的宽度为二(白色)。因此,并非所有条纹长度相等,故该照片不是一张斑马的照片。

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

首页