Submit | All submissions | Best solutions | Back to list |
GCATC - Gray Code and Twos Complement |
Let is a binary number with digits (). And we can encode it as or as , where "" is bitwise XOR operation and "" indicates the largest integer which is not greater than .
For some reasons, Chiaki encodes her password into and . Then she writes and in a paper. However, something terrible happened. A bug ate some parts of the paper, so some digits are unreadable now. Chiaki is so worried that she want you to determine the values of these digits using the readable digits.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:
There are lines of same number of digits describe and . In every line, it only contains '1', '0' and '?'. Unreadable digits are denoted with symbol '?'. Digits are given from the most significant digit to the least significant digit.
It is guaranteed that the sum of all does not exceed .
Output
For each test case, if it is impossible to restore and , you should output "IMPOSSIBLE" (without the quotes).
If is unique, you should output "UNIQUE" (without the quotes) in the first line. Then output restored and in the same format.
If there are two or more possible that can be restored using the readable digits. You should output "AMBIGUOUS" (without the quotes) and the number of possible . The number may be very large, so the answer should modulo .
Example
Input:
3 1110 0101 11?? 01?? 111? 100?
Output:
UNIQUE 1110 0101 AMBIGUOUS 3 IMPOSSIBLE
Added by: | zimpha |
Date: | 2018-01-27 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
hide comments