#P2447. [SDOI2010] 外星千足虫
[SDOI2010] 外星千足虫
Description
On February 3, , after a long journey of years and months, the re-entry capsule of the manned rocket “Genagelu-1” finally landed safely. Developed and launched by NASA, this rocket traveled past bodies in the Solar System, including Mars, Venus, Titan, Europa, Ceres, and “Zhangheng Star,” and eventually discovered extraterrestrial life on the asteroid “Jason Star.” Astronauts found a batch of precious living samples meters below the surface rock layer of “Jason Star” and brought them back for testing.
Among the living samples, the most fascinating are these alien millipedes. Their bodies are long and divided into segments. When touched, they curl into a ring and take a while before resuming activity.
There is more. Researchers found that, unlike terrestrial millipedes whose legs appear in pairs with a total even number, these aliens have a variable number of legs under each body segment, but the total number of legs is always odd.
Although they are hard to distinguish by appearance, by counting the number of legs, scientists can determine a millipede’s home planet based on parity.
As a secret agent sent by country J to NASA, you want to join the research to gather more intelligence. However, NASA’s selected researchers are all top scientists. So Charles Bolden, the NASA Administrator, set a challenge to test your ability:
There are millipedes numbered in front of you. Your task is to determine the home planet of each millipede, but you are not allowed to count their legs directly.
Each time, Charles will select some of the millipedes and put them into the Insect Feet Counter (IFC). The counter automatically sums the total number of legs inside. Charles will give you the result modulo , and also tell you which millipedes were put into the machine.
He will perform this operation times, and you should reach the conclusion as early as possible.
If, after the -th measurement, the existing data are already sufficient to uniquely determine each millipede’s identity, you should report this to Charles. If , it means the remaining measurements are unnecessary.
If even after all measurements the identities cannot be uniquely determined, you must also tell Charles that there are multiple solutions given the current data.
Input Format
The first line contains two positive integers .
The next lines give, in order, the results from Charles’s use of the counter. Each line contains a string and a number, separated by a space. The string indicates, by position, whether each millipede is put into the machine: if the -th character is , millipede is not put in; if it is , it is put in. The following number is the total number of legs modulo .
Since NASA’s experimental machines are perfectly accurate, the data are guaranteed to be consistent. That is, there is at least one solution.
Output Format
If the given data yield a unique solution, output lines. The first line outputs a positive integer not exceeding , indicating that after the -th measurement the unique solution is determined. The next lines output the identity of each millipede in order: output ?y7M# for an odd number of legs, and Earth for an even number of legs.
If the input data admit multiple solutions, output Cannot Determine.
3 5
011 1
110 1
101 0
111 1
010 1
4
Earth
?y7M#
Earth
5 7
01100 1
11000 1
10100 0
11100 1
00011 1
00000 0
11111 0
Cannot Determine
Hint
Scoring
- For each test point, if your output file exactly matches the answer file, you get full credit for that point.
- Otherwise, if the solution is unique and you correctly output the identities of all millipedes, you get of the points for that test point.
- In all other cases, you get zero for that test point.
Constraints and Conventions
- For of the test points, .
- For of the test points, .
- For of the test points, , .
- For of the test points, , .
Translated by ChatGPT 5
京公网安备 11011102002149号