CF1099C.Postcard

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.

Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.

For example, consider the following string:

This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows:

  • candy cane 1: remove the letter w,
  • snowflake 1: repeat the letter p twice,
  • candy cane 2: leave the letter n,
  • snowflake 2: remove the letter w,
  • snowflake 3: leave the letter e.

Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.

Andrey knows that messages from Irina usually have a length of kk letters. Help him to find out if a given string can encode a message of kk letters, and if so, give an example of such a message.

安德烈收到了伊琳娜寄来的一张明信片。明信片上仅有文字“你好,安德烈!”,以及一个由小写拉丁字母、雪花符号和拐杖糖符号组成的奇怪字符串。安德烈认为该字符串是一条加密信息,于是决定将其解密。

安德烈注意到,雪花符号和拐杖糖符号总是出现在字母之后,因此他推测该信息的加密方式如下:拐杖糖表示其前面的字母可被删除,也可保留;雪花符号表示其前面的字母可被删除、保留,或重复若干次。

例如,考虑以下字符串:

该字符串可以编码信息 «happynewyear»。具体操作如下:

  • 拐杖糖 1:删除字母 w,
  • 雪花 1:将字母 p 重复两次,
  • 拐杖糖 2:保留字母 n,
  • 雪花 2:删除字母 w,
  • 雪花 3:保留字母 e。

请注意,同一字符串可能编码多种不同的信息。例如,上述字符串还可编码 «hayewyar»、«happpppynewwwwwyear» 等其他信息。

安德烈知道,伊琳娜通常发送的信息长度恰好为 kk 个字母。请帮助他判断给定字符串是否能够编码一个长度为 kk 的信息;若可以,请给出一个满足条件的信息示例。

输入格式

The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed 200200.

The second line contains an integer number kk (1≤k≤2001 \leq k \leq 200), the required message length.

第一行包含明信片中收到的字符串。该字符串仅由小写拉丁字母,以及字符 «*» 和 «?» 组成,分别表示雪花和甜筒。这些字符只能紧接在字母之后出现。字符串长度不超过 200200。

第二行包含一个整数 kk(1≤k≤2001 \leq k \leq 200),表示所需消息的长度。

输出格式

Print any message of length kk that the given string can encode, or «Impossible» if such a message does not exist.

输出任意一个长度为 kk 的消息,使得给定字符串能够对其进行编码;如果不存在这样的消息,则输出 «Impossible»。

输入输出样例

  • 输入#1

    hw?ap*yn?eww*ye*ar
    12

    输出#1

    happynewyear
  • 输入#2

    ab?a
    2

    输出#2

    aa
  • 输入#3

    ab?a
    3

    输出#3

    aba
  • 输入#4

    ababb
    5

    输出#4

    ababb
  • 输入#5

    ab?a
    1

    输出#5

    Impossible

输入解题思路,AI测评打分。不知道怎么写?

首页