Seongsipdang
InterviewTime limit3sMemory limit1024 MB
List all 2^N binary strings of length N, starting from a given string, so that the total number of matching positions between consecutive strings is minimized.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Greedy, Math, Combinatorics
- Solved
- No attempts yet
Problem
Suhyeon recently opened a bakery called . Every day it bakes and sells bread that is crunchier on the outside than a cracker and moist enough to be soft on the inside, and it soon became a popular bakery that even turned into a must-visit spot for Instagram bread tours, but unfortunately the tightened distancing rules have sharply reduced the number of customers.
Following the times, Seongsipdang began taking delivery orders. Each loaf of bread contains ingredients, and each ingredient has two variations, so one of the two can be chosen. For example, the dough can be either wheat flour or whole wheat flour, and the syrup can be either maple syrup or strawberry syrup. Therefore kinds of bread can be made. As if on cue, on the first day of delivery, orders came in, and every ordered bread was of a different kind.
Even Suhyeon, however skilled at baking, could not handle orders. Fortunately, the employees of Seongsipdang can each quickly prepare one kind of ingredient, so if several employees each prepare a different ingredient at the same time, time can be saved. Therefore Suhyeon wants to reorder the orders so that the following expression is minimized.
(the number of ingredient kinds shared by the -th order and the -th order)
However, the bread of the customer who ordered first is to be made first. Given and the first customer's order, tell us in what order the orders should be processed so that the expression above is minimized.
Input
The input is given as follows.
Output
Print the orders, starting with , one per line. Each order is printed as a string of length in the same way as the input format, where the -th character is the kind of the -th ingredient.
If several orderings satisfy the condition, print any one of them.
Constraints
- is the number of ingredients in Seongsipdang bread. ()
- is the string representing the first order. The -th character is the kind of the -th ingredient, and to save bandwidth on the delivery order system, one variation is written as
0and the other as1. ()