Words 2
Time limit1sMemory limit128 MB
Given exponents k1..kn, find the smallest m such that the concatenation of h_k(0) is a substring of h_m(0), or report NIE.
- Level
Hard8 of 10
- Topics
- String, Recursion, Divide and conquer, Implementation
- Solved
- No attempts yet
Problem
Define a function that acts on binary strings (strings over the digits 0 and 1). transforms a string by replacing every 0 with 1 and every 1 with the two-character string 10, with all replacements done simultaneously and independently. For example, maps 1001 to 101110, and it maps the empty string to the empty string. The function is injective. Let denote composed with itself times; is the identity, so .
Consider the one-character string 0 and the strings for . This sequence begins:
0, 1, 10, 101, 10110, 10110101, ...
A string is a substring of a string if it occurs in as a contiguous block. Given integers , decide whether the concatenation
is a substring of for some , and if so find the smallest such .
Input
The first line contains one integer (). The second line contains non-negative integers (), separated by single spaces.
Output
Print the smallest non-negative integer such that is a substring of . If no such exists, print NIE.