#P10330. [UESTCPC 2024] 黑白珠串

[UESTCPC 2024] 黑白珠串

Problem Description

You are a craftsman in Kuanzhai Alley. One day, a customer orders a black-and-white bead string from you. The black-and-white bead string looks like a chain, with black and white beads arranged on it. The customer also gives you kk requirements, and each requirement is as follows:

  • Given x,yx, y, there must exist at least one substring in the bead string such that the substring has length xx and contains exactly yy black beads.

Here, a substring means a contiguous segment of beads in the bead string.

Please construct a black-and-white bead string that satisfies all the requirements above, and make the length of the string as small as possible. To ensure that your constructed string satisfies the requirements, you also need to give, for each requirement, the position of one substring that satisfies it.

Input Format

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

The next kk lines follow. The ii-th line contains two integers xi,yix_i,y_i (1xi106,0yixi)(1\leq x_i\leq 10^6,0\leq y_i\leq x_i), representing the ii-th requirement.

Output Format

The first line contains an integer ll, representing the minimum length of a black-and-white bead string that satisfies the requirements.

The second line contains a string consisting of 0 and 1, with length ll, representing the black-and-white bead string you constructed. Here, 0 means a white bead, and 1 means a black bead.

The next kk lines follow. The ii-th line contains an integer pip_i, representing the starting position of a substring that satisfies the ii-th requirement. The positions in the bead string are numbered starting from 00.

3
3 1
3 2
2 0
4
1100
1
0
2
4
2 1
3 3
4 0
3 2
7
1110000
2
0
3
1

Hint

Translated by ChatGPT 5