Lay out two voices of a song as a round, aligning each voice's symbols so that simultaneous sounds share a column and gaps print as plus signs.
Medium6SimulationImplementationStringNo attempts yetTime limit2sMemory limit512 MB
A round is an arrangement in which two or more voices sing the same melodic line, each voice starting at a different time. The nursery rhyme "Row, Row, Row Your Boat" shown above is a well known round: a new voice may enter when the first voice reaches any of the '*'s.
Every syllable of the song sounds for a whole number of time units. A pause, called a rest, is written as a symbol of its own and is given a duration the same way. From the duration of every symbol and the time at which the second voice enters, you can work out which symbols of the two voices sound at the same moment.
Write a program that prints a two voice round with simultaneous symbols in the same column.
The song has L lines. For line i of the song, print two output lines: the first voice line, then the second voice line.
The first voice line holds the symbols of song line i and nothing else. That line fixes one time period. The period opens when the first symbol of song line i starts sounding and closes when the last symbol of song line i stops sounding.
The second voice line holds, in time order, every symbol of the song that the second voice starts sounding inside that period. A symbol that starts exactly at the moment the period closes belongs to the next output pair, not this one. The last symbol of a second voice line may keep sounding after the period closes.
Columns are numbered from 0. Every position of an output line that no symbol covers holds a plus sign, '+'. A line ends with its last symbol, so no line ends with a plus sign. Each symbol starts in the leftmost column these rules allow:
The last two rules compare one voice against the other. Between two symbols of the same voice only the separation rule applies, never the difference of their start times.
A second voice line can be empty, and then an empty line is printed. Some symbols of the second voice are never printed.
The first line holds two integers L and N. L is the number of lines in the song, 0<L≤10. N is the time at which the second voice enters, with the first voice entering at time zero, 0≤N≤128.
L pairs of lines follow.
The first line of each pair holds the symbols of that line of the song. A symbol is a string of non-whitespace characters, and a single blank separates adjacent symbols. Each of these lines is at most 80 characters long.
The second line of each pair holds one positive integer per symbol of the line above, in the same order, giving the time allocated to that symbol. Each integer is in the range 1…128.
Print 2L lines, two lines for each line of the song, as described above.