Find the Double Class
Time limit1sMemory limit256 MB
Given M distinct rows of N section numbers, output at most M new rows so that each input row agrees with some new row in every column, yet no new row equals an input row.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
members of Cycom are all taking the same courses this year, and the number of courses they take is . Even for the same course there are several sections, and only people in the same section attend the lecture together. Surprisingly, all members are in different sections, so no pair of them attends even one class together.
To escape loneliness, the Cycom members decide to create imaginary friends. Each friend will take the same set of courses as the Cycom members, and their sections can be chosen freely. The goal is to make every person attend every course together with an imaginary friend.
can be chosen freely, but an imaginary friend must not outnumber real humans, so must hold. Also, for each Cycom member, there must not exist an imaginary friend whose course section numbers all match exactly.
Input
The first line gives the number of courses and the number of members .
From the second line to the -th line, the -th line gives the integers . is the section number of course taken by member .
Output
The first line prints the number of imaginary friends .
From the second line to the -th line, the -th line prints the integers . is the section number of course taken by imaginary friend .
Constraints
- For all and , . (In other words, the Cycom members have no overlapping sections in any course.)
- For all and , there must exist at least one with such that . (In other words, for each Cycom member, there must not exist an imaginary friend whose course section numbers all match exactly.)
- For all and , there must exist at least one with such that . (In other words, each Cycom member must be able to attend every course together with at least one imaginary friend.)