#P7285. 「EZEC-5」修改数组

「EZEC-5」修改数组

Description

Given an array of length nn whose elements are 00 or 11.

Now you may choose some (possibly 00) elements with value 00 and change them to 11.

Let:

  • xx be the length of the longest consecutive subarray of 11s (by definition, if all numbers are 00, then x=0x = 0);
  • yy be the number of modified elements.

Find how to modify the array to maximize xyx - y, and construct one valid plan (output the modified array).

Input Format

This problem contains multiple test cases.

The first line contains an integer TT indicating the number of test cases.

The next 2×T2 \times T lines describe the test cases, where every 22 lines correspond to one test case.

In each test case, the first line contains an integer nn, the length of the array.

The second line contains nn integers (00 or 11), representing the given array.

Output Format

Output a total of 2×T2 \times T lines, where every 22 lines correspond to one test case.

In each test case, on the first line output an integer, the maximum value of xyx - y.

On the second line output nn integers (00 or 11), representing the modified array. If there are multiple solutions, output any one of them.

1
1
1
1
1
2
3
1 0 1
5
0 1 0 1 0
2
1 1 1
2
0 1 1 1 1

Hint

This problem uses bundled tests.

For all testdata, it is guaranteed that T10T \le 10 and 1n1051 \le n \le 10^5, and the array elements {0,1}\in \{0,1\}.

  • Subtask 1 (70 points): 1n101 \le n \le 10.
  • Subtask 2 (30 points): no additional constraints.

Translated by ChatGPT 5