#P2447. [SDOI2010] 外星千足虫

    ID: 1476 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2010各省省选山东概率论,统计高斯消元位运算,按位

[SDOI2010] 外星千足虫

Description

On February 3, 23332333, after a long journey of 1717 years and 33 months, the re-entry capsule of the manned rocket “Genagelu-1” finally landed safely. Developed and launched by NASA, this rocket traveled past 2323 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 45.7045.70 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 NN millipedes numbered 1N1 \ldots N 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 NN 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 22, and also tell you which millipedes were put into the machine.

He will perform this operation MM times, and you should reach the conclusion as early as possible.

If, after the KK-th measurement, the existing data are already sufficient to uniquely determine each millipede’s identity, you should report this KK to Charles. If K<MK<M, it means the remaining MKM-K measurements are unnecessary.

If even after all MM 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 N,MN, M.

The next MM lines give, in order, the MM results from Charles’s use of the counter. Each line contains a 0101 string and a number, separated by a space. The 0101 string indicates, by position, whether each millipede is put into the machine: if the ii-th character is 00, millipede ii is not put in; if it is 11, it is put in. The following number is the total number of legs modulo 22.

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 N+1N+1 lines. The first line outputs a positive integer KK not exceeding MM, indicating that after the KK-th measurement the unique solution is determined. The next NN 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 50%50\% of the points for that test point.
  • In all other cases, you get zero for that test point.

Constraints and Conventions

  • For 20%20\% of the test points, N=M20N=M\leq 20.
  • For 40%40\% of the test points, N=M500N=M\leq 500.
  • For 70%70\% of the test points, N500N\leq 500, M103M\leq 10^3.
  • For 100%100\% of the test points, 1N1031\leq N\leq 10^3, 1M2×1031\leq M\leq 2\times 10^3.

Translated by ChatGPT 5