Two Doors
InterviewTime limit1sMemory limit1024 MB
Given n doors and m switches that flip doors, find a set of switches that makes the passage shift time by each i from -n to n years, or report that none exists.
- Level
Medium4 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Dodo set out to find Ea, who was swept away by a storm across space and time. Dodo knows only that Ea is between years and years in the future from now. While searching for a time machine, Dodo learned about a strange door from the evil Black Wizard.
The door has a front side and a back side. The front side is always 1 year ahead of the back side. In other words, going through the door from front to back takes you 1 year into the past, and going through from back to front takes you 1 year into the future.
The devilish Black Wizard would not simply give Dodo the door. Instead, he offered a passage made of doors joined together. After long study, Dodo installed switches, each of which turns a specific combination of doors 180 degrees. Now let us use these switches to rescue Ea!
Input
The first line contains () and ().
The second line contains a string of length made only of 0 and 1. The -th character gives the initial state of the -th door. 0 means the front side faces Dodo, and 1 means the back side faces Dodo.
From the third line to line , there are strings of length made only of 0 and 1. The -th character of the -th line tells whether switch turns door 180 degrees. 0 means it does not turn the door, and 1 means it does.
Output
Print lines in total. For every , print the answer for trying to go years into the future on line .
On each line, if a solution exists, print the number () of switches to press, followed by the switch numbers separated by spaces. If no solution exists, print -1.
If there are several combinations of switches to press, print any one of them.
Hint
In the figure, red means the front side of a door faces you and blue means the back side faces you. The upper passage in the figure is the initial state. Passing through this passage takes you years into the future, that is, 3 years into the past. Pressing switch 2 changes the passage to the lower one. Passing through that passage takes you 1 year into the future.
