410226: GYM103987 B Rule 110

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Rule 110time limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

The Rule 110 cellular automaton (often called simply Rule 110) is an elementary cellular automaton with interesting behavior on the boundary between stability and chaos. In this respect, it is similar to Conway's Game of Life. Like Life, Rule 110 is known to be Turing complete. This implies that, in principle, any calculation or computer program can be simulated using this automaton.

The Rule 110 is famous for its interesting properties. Among the 88 possible unique elementary cellular automata, Rule 110 is the only one for which Turing completeness has been proven, although proofs for several similar rules should follow as simple corollaries (e.g. Rule 124, which is the horizontal reflection of Rule 110). Rule 110 is arguably the simplest known Turing complete system.

This paragraph will introduce how Rule 110 works. When applying Rule 110 to a pattern, whether each point in the pattern will be 0 or 1 in the new generation depends on its current value, and on the values of its two neighbors. If a point is at the left/right border, then the left/right neighbor of it will be considered as 0. The rules are as follows:

Current pattern000001010011100101110111
New state for center cell01110110

Chipmunk is interested in the automaton but he is not clever enough to solve it quickly. Now Chipmunk gives you the initial pattern, and you need to apply Rule 110 to the pattern once and output the result.

Input

The first line contains an integer $$$n\ (1\le n\le 10^5)$$$, the length of the pattern.

The next line is a string of length $$$n$$$ consisting of only 0s and 1s, representing the initial pattern.

Output

Output a string of length $$$n$$$, the pattern after applying Rule 110.

Scoring

The problem contains several subtasks. You can get the corresponding score for each passed test case.

  • Subtask 1 ($$$40$$$ points): $$$n\le 1000$$$.
  • Subtask 2 ($$$60$$$ points): no additional constraints.
ExamplesInput
1
1
Output
1
Input
8
00111010
Output
01101110
Note

In the first example, there is an only 1 in the initial pattern. The two neighbors of it are both 0, which satisfies pattern 010. According to the table above, the value of the point will stay at 1.

加入题单

上一题 下一题 算法标签: