Go++ (Large)
Time limit5sMemory limit512 MB
Decide whether two bounded Go++ programs can jointly print every good string while never printing the bad string, and construct them by the given rule.
- Level
Hard8 of 10
- Topics
- Implementation, Simulation, Greedy
- Solved
- No attempts yet
Problem
The Go language was designed to have a simple API and to support multi-threading. The Code Jam team wants to push these goals to the limit, so we are proposing a new language called Go++.
The Go++ language uses one register, which stores one boolean value (0 or 1). This register is initialized to 0. The language has three instructions:
0, which sets the register to 0.1, which sets the register to 1.?, which prints the current register value.
To support multi-threading, two different Go++ programs may run simultaneously while sharing the one register. Each instruction executes atomically, that is, one instruction must completely finish before the next instruction can start. However, the two programs may be interleaved in any way that preserves the relative order within each program.
For example, here are the only six ways in which the two programs 1? and ?0 could be executed together. The instructions of the second program are wrapped in square brackets to distinguish them from the instructions of the first program.
[?][0]1?, which prints01. (Remember that the register is initialized to 0.)[?]1[0]?, which prints00.[?]1?[0], which prints01.1[?][0]?, which prints10.1[?]?[0], which prints11.1?[?][0], which prints11.
The printed string always consists of 0s and 1s, since the register can only hold 0 or 1.
Usually, programmers write programs to produce a desired output, but your task is to write two programs that won't produce an undesired output. You are given a "bad" string B of length L and a set G of N "good" strings, all of length L. You must produce two Go++ programs (not necessarily of the same length) which, when run in the way described here, could produce every string in G but could not produce the string B, no matter how they are interleaved. It is fine if the programs could also produce other strings that are not B and not in G. There must be a combined total of exactly L ? instructions in the two programs, and the combined number of instructions in the two programs must not exceed 200.
For example, for B = 11 and G = { 10, 00 }, the programs ? and 10?1 would be one valid answer. They can produce every string in G, but they cannot produce B, no matter how they are interleaved. (They can also produce the string 01, which is not B and is not in G, but that is fine.) However, the programs 1? and ?0 would not be a valid answer, since (as shown above) they can produce B. The programs 00 and ?? would not be a valid answer either, since they cannot produce every string in G.
Produce two programs that satisfy the conditions, or determine that the task is IMPOSSIBLE.
Input
The first line of the input gives the number of test cases, T. T test cases follow; each consists of three lines. The first line of each test case has two integers N and L: the number of strings in G, and the length of B and of the strings in G. The second line has N different strings of length L separated by spaces: the strings in G. The third line has one string of length L: the bad string B. B and all of the strings in G consist only of 0s and 1s.
Limits
- All strings in G are different.
- B may be any string consisting of
0s and1s.
Output
For each test case, output one line. If no pair of programs satisfies the conditions, output Case #x: IMPOSSIBLE. Otherwise, output Case #x: y z, where x is the test case number (starting from 1) and y and z are the two programs built by the rule below.
Let be the -th character of B, and let be the flipped character (1 if is 0, and 0 if is 1).
yis the program of length formed by concatenating followed by?for in order.- If ,
zis the program of length formed by concatenating followed by for in order. If ,zis the single instruction .
Whenever some pair of programs satisfies the conditions, the pair built by this rule also satisfies them. For example, for B = 11, y is 0?0? and z is 01.
Hint
Sample case #1 is the one described in the problem statement. The programs ? and 10?1 from the statement also satisfy the conditions, but the required output follows the rule above and is 0?0? 01.
Sample case #3 is obviously IMPOSSIBLE because B is in G.