P28039 [洛谷] [UESTCPC 2024] Black and White Bead String
普及
题目描述

Problem Description

You are a craftsman in the Wide and Narrow Alleys. Today, a customer orders a black and white bead string from you. The bead string is shaped like a chain, with black and white beads arranged in a sequence. The customer also presents you with $k$ conditions, each as follows:

  • Given $x, y$, the black and white bead string must contain at least one substring where the length of the substring is $x$ and it contains exactly $y$ black beads.

Here, a substring refers to a continuous segment of beads in the black and white bead string.

Please construct a black and white bead string that meets all the above conditions and has the smallest possible length. To ensure that the constructed bead string meets the conditions, you also need to provide the starting position of a substring that satisfies each condition.

Input Format

The first line contains an integer $k$ $(1 \leq k \leq 10^5)$, representing the number of conditions.

The next $k$ lines each contain two integers $x_i, y_i$ $(1 \leq x_i \leq 10^6, 0 \leq y_i \leq x_i)$, representing the content of the conditions.

Output Format

The first line contains an integer $l$, representing the minimum length of the black and white bead string that meets the conditions.

The second line contains a string composed of 0 and 1, with a length of $l$, representing the constructed black and white bead string. Here, 0 represents a white bead, and 1 represents a black bead.

The next $k$ lines each contain an integer $p_i$, representing the starting position of a substring in the bead string that satisfies the $i$-th condition. Positions in the bead string are numbered starting from $0$.

Sample Input and Output

Sample Input #1

3
3 1
3 2
2 0

Sample Output #1

4
1100
1
0
2

Sample Input #2

4
2 1
3 3
4 0
3 2

Sample Output #2

7
1110000
2
0
3
1
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 1 3 2 2 0
样例输出
4 1100 1 0 2