CF1031E.Triple Flips

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of length nn that consists of zeros and ones.

You can perform the following operation multiple times. The operation consists of two steps:

  1. Choose three integers 1≤x<y<z≤n1 \le x \lt y \lt z \le n, that form an arithmetic progression (y−x=z−yy - x = z - y).
  2. Flip the values ax,ay,aza_x, a_y, a_z (i.e. change 11 to 00, change 00 to 11).

Determine if it is possible to make all elements of the array equal to zero. If yes, print the operations that lead the the all-zero state. Your solution should not contain more than (⌊n3⌋+12)(\lfloor \frac{n}{3} \rfloor + 12) operations. Here ⌊q⌋\lfloor q \rfloor denotes the number qq rounded down. We can show that it is possible to make all elements equal to zero in no more than this number of operations whenever it is possible to do so at all.

给你一个长度为 nn 的数组 aa,其中每个元素均为 00 或 11。

你可以执行以下操作若干次。每次操作包含两个步骤:

  1. 选择三个满足 1≤x<y<z≤n1 \le x \lt y \lt z \le n 的整数,使得它们构成等差数列(即满足 y−x=z−yy - x = z - y);
  2. 翻转 ax,ay,aza_x, a_y, a_z 的值(即将 11 变为 00,将 00 变为 11)。

判断是否能通过若干次操作使数组所有元素均变为 00。如果可以,请输出将数组变为全零状态所需的操作序列。你的解法所含操作次数不得超过 (⌊n3⌋+12)(\lfloor \frac{n}{3} \rfloor + 12) 次。其中 ⌊q⌋\lfloor q \rfloor 表示对实数 qq 向下取整。可以证明:只要存在一种方案能将数组变为全零状态,则一定存在一种操作次数不超过该上限的方案。

输入格式

The first line contains a single integer nn (3≤n≤1053 \le n \le 10^5) — the length of the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10 \le a_i \le 1) — the elements of the array.

第一行包含一个整数 nn(3≤n≤1053 \le n \le 10^5)—— 数组的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10 \le a_i \le 1)—— 数组的元素。

输出格式

Print "YES" (without quotes) if the answer exists, otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).

If there is an answer, in the second line print an integer mm (0≤m≤(⌊n3⌋+12)0 \le m \le (\lfloor \frac{n}{3} \rfloor + 12)) — the number of operations in your answer.

After that in (i+2i + 2)-th line print the ii-th operations — the integers xi,yi,zix_i, y_i, z_i. You can print them in arbitrary order.

如果答案存在,输出 "YES"(不带引号);否则输出 "NO"(不带引号)。每个字母可使用任意大小写(大写或小写)。

如果答案存在,则在第二行输出一个整数 mm(0≤m≤(⌊n3⌋+12)0 \le m \le (\lfloor \frac{n}{3} \rfloor + 12)),表示你所给出的答案中操作的次数。

随后,在第 (i+2)(i + 2) 行输出第 ii 个操作——三个整数 xi,yi,zix_i, y_i, z_i。这三个数的输出顺序可以任意。

输入输出样例

  • 输入#1

    5
    1 1 0 1 1

    输出#1

    YES
    2
    1 3 5
    2 3 4
  • 输入#2

    3
    0 1 0

    输出#2

    NO

说明/提示

In the first sample the shown output corresponds to the following solution:

  • 1 1 0 1 1 (initial state);
  • 0 1 1 1 0 (the flipped positions are the first, the third and the fifth elements);
  • 0 0 0 0 0 (the flipped positions are the second, the third and the fourth elements).

Other answers are also possible. In this test the number of operations should not exceed ⌊53⌋+12=1+12=13\lfloor \frac{5}{3} \rfloor + 12 = 1 + 12 = 13.

In the second sample the only available operation is to flip all the elements. This way it is only possible to obtain the arrays 0 1 0 and 1 0 1, but it is impossible to make all elements equal to zero.

在第一个样例中,所展示的输出对应于以下解法:

  • 1 1 0 1 1(初始状态);
  • 0 1 1 1 0(翻转的位置为第 1、第 3 和第 5 个元素);
  • 0 0 0 0 0(翻转的位置为第 2、第 3 和第 4 个元素)。

其他答案也是可行的。在本测试用例中,操作次数不应超过 ⌊53⌋+12=1+12=13\lfloor \frac{5}{3} \rfloor + 12 = 1 + 12 = 13。

在第二个样例中,唯一允许的操作是翻转所有元素。因此,仅能获得数组 0 1 0 和 1 0 1,但无法使所有元素都变为零。

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

首页