Problem list
Log in
#icpc00112 · ICPC SWERC 2020

Rule 110

Unrated 3.0 s 2048 MB

3

Ann is decorating her office with the coolest arrangement of lights ever. She is using very long LED strips, where each individual cell is switched on or off every second, according to the following simple and pretty algorithm. At each step, the status of each cell (0 for off and 1 for on) is determined from the status of its two neighbor cells on the strip (left and right) and its own status, according to the following table:

Current pattern | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 New state for center cell | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0

Ann is choosing an initial configuration for the cells and she marvels at the resulting animation, which happens to be highly similar to Conway's Game of Life, with interesting behavior on the boundary between stability and chaos.

Input

The input is composed of two lines.

  • The first line contains the initial configuration, as a string of 16 characters 0 and 1. All the cells to the left and to the right of this string are considered to be 0.
  • The second line contains the number $N$ of steps to perform.

Output

The output should contain a single line with a single integer that is the total number of 1-cells in the final configuration.

Example 1

Input
0001001101111100
5
Output
11
Source
ICPC SWERC 2020
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code