Schedule
Time limit2sMemory limit1024 MB
Schedule one member per team each week so every pair of people from different teams meets, minimizing the longest gap between their meetings.
- Level
Hard9 of 10
- Topics
- Combinatorics, Bit manipulation, Math
- Solved
- No attempts yet
Problem
The Institute for Creative Product Combinations (ICPC) searches for unusual, innovative ways to join products or technologies that seem unrelated. These combinations open new markets and create jobs. For example, its latest success was the 'hairbachi', a hair dryer with a hibachi grill top attachment for cooking hot meals on the go.
The company employs teams of two people each. Each team first researches its own products. Then members of different teams meet to explore ways to combine products.
During the pandemic, ICPC management scheduled everyone so that never more than people were in the office at the same time. Things ran smoothly, so they kept the process after normal operations resumed. The scheme works as follows. Label the teams through and the two people on team as and . Each week, exactly one person from each team comes into the office, while the other stays away. The members and know each other well and collaborate productively while isolated, so they do not need to meet in the office. However, isolation between members of different teams is still a concern.
Each pair of teams and with has to collaborate occasionally. For a given number of weeks and fixed team members and , let be the weeks in which these two people meet in the office. The isolation of those two people is the maximum of , or infinity if they never meet. The isolation of the whole company is the maximum isolation across all choices of , , , and .
Find a weekly schedule that minimizes the isolation of the whole company over weeks.
Input
A single line with two integers () and (), where is the number of teams and is the number of weeks to schedule.
Output
Print one line with the minimum isolation achievable for teams, or the word infinity if no schedule guarantees that every pair of people from different teams meets. If the isolation is finite, print more lines giving a schedule that achieves it. The th line is a string of length using only the symbols 1 and 2, where the th symbol shows which member of team comes into the office in week .