#P7254. [BalticOI 2012] 旋律 (Day2)
[BalticOI 2012] 旋律 (Day2)
Description
There is a little-known musical instrument. It has holes, and by covering these holes in ten different ways to , it can produce notes. You are not allowed to use any hole-covering pattern other than those for these notes.
Now you want to play a piece of music, but because this instrument requires that between any two consecutive notes, the hole-covering patterns differ in at most holes, you may have to play some notes incorrectly. You want to minimize the number of notes you play incorrectly.
Input Format
The first line contains three integers , as described above.
The next lines each contain a string of length (digits only), representing the hole-covering pattern when playing that note.
The next line contains an integer , the number of notes in the piece.
The last line contains integers, representing the indices of the notes in the piece.
Output Format
The first line contains one integer, the minimum possible number of notes that you play incorrectly.
The next line contains integers, representing any one valid construction of your playing plan.
5 4 2
1111
2101
2000
0100
0000
7
1 5 4 5 3 2 1
1
1 2 4 5 3 2 1
Hint
Sample Explanation
Note and note have different playing patterns on all four holes, so you cannot play note right after playing note .
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Notes
Translated from BalticOI 2012 Day2 T2. Melody.
Translated by ChatGPT 5
京公网安备 11011102002149号