Codeforces Round 193 (Div. 2)
E
Binary Key
Codeforces
2400
原题
← D→
翻译中…

Let's assume that $*p*$ and $*q*$ are strings of positive length, called the container and the key correspondingly, string $*q*$ only consists of characters 0 and 1. Let's take a look at a simple algorithm that extracts message $*s*$ from the given container $*p*$:

翻译中…

i = 0;
j = 0;
s = <>;
while i is less than the length of the string p
{
    if q[j] == 1, then add to the right of string s character p[i];
    increase variables i, j by one;
    if the value of the variable j equals the length of the string q, then j = 0;
}

翻译中…

In the given pseudocode $*i*$, $*j*$ are integer variables, $*s*$ is a string, '=' is an assignment operator, '==' is a comparison operation, '[]' is the operation of obtaining the string character with the preset index, '<>' is an empty string. We suppose that in all strings the characters are numbered starting from zero.

翻译中…

We understand that implementing such algorithm is quite easy, so your task is going to be slightly different. You need to construct the lexicographically minimum key of length $*k*$, such that when it is used, the algorithm given above extracts message $*s*$ from container $*p*$ (otherwise find out that such key doesn't exist).

翻译中…

Input

翻译中…

The first two lines of the input are non-empty strings $*p*$ and $*s*$ ($1 ≤ |*p*| ≤ 10^{6}$, $1 ≤ |*s*| ≤ 200$), describing the container and the message, correspondingly. The strings can contain any characters with the ASCII codes from 32 to 126, inclusive.

翻译中…

The third line contains a single integer $*k*$ ($1 ≤ *k* ≤ 2000)$ — the key's length.

翻译中…

Output

翻译中…

Print the required key (string of length $*k*$, consisting only of characters 0 and 1). If the key doesn't exist, print the single character 0.

翻译中…

Note

翻译中…

String $*x* = *x*_{1}*x*_{2}... *x*_{*p*}$ is lexicographically smaller than string $*y* = *y*_{1}*y*_{2}... *y*_{*q*}$, if either $*p* < *q*$ and $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ... , *x*_{*p*} = *y*_{*p*}$, or there exists such integer $*r*$ ($0 ≤ *r* < *min*(*p*, *q*))$ that $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ... , *x*_{*r*} = *y*_{*r*}$ and $*x*_{*r* + 1} < *y*_{*r* + 1}$. Symbols are compared according to their ASCII codes.

翻译中…

样例

Input #1
abacaba
aba
6
Output #1
100001
InputCopy OutputCopy
Input #2
abacaba
aba
3
Output #2
0
InputCopy OutputCopy
题目信息
题号
332E
时间限制
4 s
内存限制
256 MB
标签
动态规划
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。