#P12296. [ICPC 2023 WF] Schedule

[ICPC 2023 WF] Schedule

题目描述

The Institute for Creative Product Combinations (ICPC) tries to find unusual and innovative ways to unite seemingly unrelated products or technologies, opening up new markets and creating new jobs. (For instance, their most recent success was the "hairbachi," a hair-dryer with a hibachi grill top attachment for preparing on-the-go hot meals.) The company employs nn teams of size 22 to research individual products, then members of the different teams get together to explore ways of combining products.

During the pandemic, the ICPC management organized everyone's schedule in such a way that there were never more than nn people in the office at the same time, and things ran so smoothly that they continued the process once things began to return to normal. Here is the scheme they used. Label the teams with integers 11 through nn and the two people on the ithi^\text{th} team as (i,1)(i, 1) and (i,2)(i, 2) for each ii from 11 to nn. Each week, exactly one person from each team is allowed in the office, while the other has to stay away. The employees (i,1)(i, 1) and (i,2)(i, 2) know each other well and collaborate productively regardless of being isolated from each other, so members of the same team do not need to meet in person in the office. However, isolation between members from different teams is still a concern.

Each pair of teams ii and jj for iji \neq j has to collaborate occasionally. For a given number ww of weeks and for fixed team members (i,a)(i, a) and (j,b)(j, b), let w1<w2<<wkw_1 < w_2 < \ldots < w_k be the weeks in which these two team members meet in the office. The isolation of those two people is the maximum of

$$\{w_1,w_2-w_1,w_3-w_2,\ldots,w_k-w_{k-1},w+1-w_k\} $$

or infinity if those two people never meet. The isolation of the whole company is the maximum isolation across all choices of ii, jj, aa, and bb.

You have been tasked to find a weekly schedule that minimizes the isolation of the whole company over a given number ww of weeks.

输入格式

The input consists of a single line containing two integers nn (2n1042 \le n \le 10^4) and ww (1w521 \le w \le 52), where nn is the number of teams and ww is the number of weeks that need to be scheduled.

输出格式

Output a line containing either an integer representing the minimum isolation achievable for nn teams or the word infinity if no schedule guarantees that every pair of individuals on different teams can meet. If the isolation is finite, it is followed by ww lines representing a schedule that achieves this isolation. The jthj^\text{th} line of the schedule is a string of length nn containing only the symbols 1 and 2, where the ithi^\text{th} symbol indicates which of the two members from team ii comes into the office on week jj.

2 6

4
11
12
21
22
11
12

2 1

infinity