Jumpers
Time limit1sMemory limit128 MB
Decide whether a set of distinct white start cells and closed jump sequences can cover every white cell without landing on any black cell.
- Level
Hard8 of 10
- Topics
- Graph, Number theory, Math, Greedy
- Solved
- No attempts yet
Problem
A cyclic tape has cells. Some are painted black and some white. Your task is to paint every cell black. To paint them you use jumpers: hopping robots dipped in black paint. When a jumper lands on a white cell, it repaints that cell black. A jumper may never land on a black cell. You may use any number of jumpers, and for each jumper you pick any white cell as its start; the chosen starting cells must be pairwise distinct.
Every jumper must make at least one jump and finish back on the cell it started from. A jumper paints its own starting cell only on its final jump. All jumpers are identical: they share one set of possible jumps . From its current cell a jumper may perform any one of the moves, as long as that jump obeys the rules above. The -th move sends the jumper cells clockwise.
For a given tape and jumper specification, decide whether it is possible to repaint the whole tape black while respecting all of the rules above.
Input
The first line contains an integer (), the number of test sets. The test sets follow.
Each test set begins with a line holding two integers and (, ): is the tape length and is the number of possible jump lengths. The next line is a string of characters B and C describing the cyclic tape (B is a white cell, C is a black cell). Each of the following lines holds one integer (), one of the jumper's possible jump lengths.
Output
For each test set output one line with a single word: TAK if the tape can be painted entirely black, or NIE otherwise.