301761: CF332E. Binary Key

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Binary Key

题意翻译

给你两个字符串p和s,让你求出一个字典序尽量小的长度为k的01串密钥,能将p转化为s。 密钥的工作方式如下: 第i位是0,表示这一位无用; 第i位是1,表示这一位有用。 若密钥的长度比p短,则可以通过循环的方式补齐。

题目描述

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 $ : `<br></br>i = 0;<br></br>j = 0;<br></br>s = <>;<br></br>while i is less than the length of the string p<br></br>{<br></br> if q[j] == 1, then add to the right of string s character p[i];<br></br> increase variables i, j by one;<br></br> if the value of the variable j equals the length of the string q, then j = 0; <br></br>}<br></br>`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).

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #1

abacaba
aba
6

输出样例 #1

100001

输入样例 #2

abacaba
aba
3

输出样例 #2

0

说明

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

Input

题意翻译

给你两个字符串p和s,让你求出一个字典序尽量小的长度为k的01串密钥,能将p转化为s。 密钥的工作方式如下: 第i位是0,表示这一位无用; 第i位是1,表示这一位有用。 若密钥的长度比p短,则可以通过循环的方式补齐。

加入题单

算法标签: