cfg

Time limit: 0.5s Memory limit: 128MB Input: Output:

Task

Consider a function FF, which takes in a string and outputs a string, having the following properties:

  • For every string xx, x<F(x)|x| < |F(x)|.
  • For every strings xx and yy, F(xy)=F(x)F(y)F(xy) = F(x)F(y), where xyxy is xx concatenated with yy.

We will also construct a set of strings, LL, in the following manner:

  • BB is in LL.
  • If xx is in LL then F(x)F(x) is also in LL.
  • If xx and yy are both in LL then xyxy is also in LL.

You are given a string BB and a list, AA, of NN strings. Knowing that BB is in LL, determine for each string from AA if it belongs to LL or not.

You will have to write a function with the following head:

std::string check (std::string (*F)(std::string), std::string B, std::vector<std::string> A)

The function should return a string, where the ithi-th character in '1' if the ithi-th string from AA belongs to LL and '0' otherwise.

Note that you only have the implement the check function, but you can also implement additional helping functions and / or structures or classes.

Please refer to the sample implementation (sample.cpp).

Input

The check function gets the following three arguments (in this particular order):

  • The FF function.
  • The string BB.
  • The array of strings AA.

All the strings will only contain lowercase English alphabet letters.

For tests worth 1010 points: the length of the longest string from A10A \le 10.

For tests worth 3030 more points: the length of the longest string from A1000A \le 1000.

For tests worth 1010 more points: BB only contains 'a's and FF only returns strings containing 'a's.

For tests worth 5050 more points: B105|B| \le 10^5, the length of the longest string from A105A \le 10^5.

For every testcase, AA contains at most 2020 strings.

Output

The check function returns a string of length equal to the length of AA, where the ithi-th character is 1'1' or 0'0' depending on whether or not the string A[i]A[i] is in LL.

Notes

Given its special type, this problem doesn't have a formal sample test case with a sample output. Here we present and explain the sample test.

Let's consider BB = abab and F(B)=abbaF(B) = abba. Then:

  • abab is in LL.
  • abababab is in LL.
  • abbaabba is in LL.
  • ababbaababba is in LL.
  • abbcabbc is not in LL.
  • abbabb is not in LL.
  • cdcd is not in LL.
  • ...

Log in or sign up to be able to send submissions!