#P7047. 「MCOI-03」数据

    ID: 5845 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索高精度O2优化剪枝洛谷月赛

「MCOI-03」数据

Description

Below are some common definitions. If you are already familiar with them, you may skip this part.

A 01 string is a string that contains only the two characters 0 and 1. It is also allowed to contain only one of them.

Taking a consecutive segment of a string is called a substring. It is easy to see that a string of length 2n2n has n+1n+1 substrings of length nn.

The mean value of a set of real numbers AA is A=xAxA\overline{A}=\frac{\sum_{x\in A}x}{|A|}, that is, the sum of all elements divided by the number of elements.

Based on this, the variance of AA is S2=xA(xA)2AS^2=\frac{\sum_{x\in A}(x-\overline{A})^2}{|A|}, that is, the sum of squared differences between each element and the mean, divided by the number of elements.

The binary value of a 01 string SS of length nn is i=1nSi2ni\sum_{i=1}^nS_i2^{n-i}, where SiS_i is the digit on the ii-th character of SS from left to right.

In this problem, we define the following:

A piece of data is a 01 string of length 2n2n.

The "toxic level" of a piece of data is defined as the variance of the binary values of all its substrings of length nn.

Now, you are given the first nn characters of a piece of data. You need to find the last nn characters such that the "toxic level" of the whole data is minimized. If there are multiple solutions, output them sorted by the binary value of the substring formed by these last nn characters, from small to large.

Input Format

The input contains one line, a 01 string of length nn, representing the first nn characters of a piece of data.

Output Format

Output several lines. Each line contains a 01 string of length nn, representing the last nn characters of a piece of data with minimum "toxic level". Output them sorted by their binary values in increasing order.

10
10

Hint

Explanation for Sample 1

In this example, n=2n=2. There are four pieces of data that satisfy the requirement: 1000, 1001, 1010, 1011.

1010 has three substrings of length 22: 10, 01, 10. Their binary values are 2,1,22,1,2. The mean of 2,1,2{2,1,2} is 53\frac{5}{3}, and the variance is 29\frac{2}{9}. Therefore, the "toxic level" of 1010 is 29\frac{2}{9}.

You can compute that the "toxic levels" of these four pieces of data are 89,23,29,23\frac{8}{9},\frac{2}{3},\frac{2}{9},\frac{2}{3}, respectively. Among them, 1010 is the only one with the minimum "toxic level", so the program outputs its last 22 characters 10.

Constraints and Notes

It is guaranteed that all testdata are generated randomly. For each bit of the 01 string, the probability of being 1 is 12\frac{1}{2}, and different bits are independent.

This problem does not use bundled tests. It is scored by test points. Test point 11 is worth 11 point, and each other test point is worth 33 points.

For each test point, the size of nn is given in the table below:

Test Point ID 11 272\sim 7 8138\sim 13 141614\sim 16
nn 3\le 3 20\le20 =26=26 =56=56
Test Point ID 172017\sim 20 212421\sim 24 252825\sim 28 293429\sim 34
nn =200=200 =500=500 1000\le1000 1500\le 1500

Note: In C++, you can use the 128128-bit integer __int128.

Translated by ChatGPT 5