아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Rule 110

시간 제한3초메모리 제한512 MB

요약
16칸짜리 초기 배치와 N이 주어질 때, 세포 자동자 규칙 110을 N번 적용한 뒤 켜진 칸의 개수를 구한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 비트 연산, 수학
정답자
아직 제출이 없습니다

문제

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 pattern111110101100011010001000
New state for center cell01101110

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.

입력

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 NN of steps to perform.

출력

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

제한

  • 0≤N<2600 \le N < 2^{60}
  • The LED strip is considered to be large enough to ensure that no 1-cells will ever reach the ends of the strip.

예제1

  1. 예제 1

    입력
    0001001101111100
    5
    
    예상 출력
    11