CF54D.Writing a Song
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One of the Hedgehog and his friend's favorite entertainments is to take some sentence or a song and replace half of the words (sometimes even all of them) with each other's names.
The friend's birthday is approaching and the Hedgehog decided to make a special present to his friend: a very long song, where his name will be repeated many times. But try as he might, he can't write a decent song!
The problem is that the Hedgehog has already decided how long the resulting sentence should be (i.e. how many letters it should contain) and in which positions in the sentence the friend's name should occur, and it must not occur in any other position in the sentence. Besides, the Hedgehog decided to limit himself to using only the first K letters of an English alphabet in this sentence (so it will be not even a sentence, but one long word).
The resulting problem is indeed quite complicated, that's why the Hedgehog asks you to help him and write a program that will make the desired word by the given name P, the length N of the required word, the given positions of the occurrences of the name P in the desired word and the alphabet's size K. Note that the occurrences of the name can overlap with each other.
刺猬和他的朋友最喜爱的娱乐活动之一,就是取某句话或某首歌,然后将其中一半(有时甚至是全部)的单词替换成彼此的名字。
朋友的生日即将来临,刺猬决定为朋友准备一份特别礼物:一首非常长的歌,其中会反复出现朋友的名字。但他绞尽脑汁,却始终写不出一首像样的歌!
问题在于,刺猬已经预先确定了最终句子的长度(即它所包含的字母总数),以及朋友的名字 P 在该句子中必须出现的位置——且名字 P 不得出现在任何其他位置。此外,刺猬还决定,整句话中仅允许使用英文字母表的前 K 个字母(因此这甚至算不上一句“话”,而只是一个超长的“单词”)。
这个问题确实相当复杂,因此刺猬请求你帮助他编写一个程序:给定朋友的名字 P、所需单词的长度 N、名字 P 在目标单词中必须出现的位置列表,以及所用字母表的大小 K,构造出满足所有条件的单词。注意:名字 P 的不同出现位置可以相互重叠。
输入格式
The first line contains numbers N and K which are the length of the required string and the alphabet size accordingly. The limitations are: 1 ≤ N ≤ 100, 2 ≤ K ≤ 26.
The second line contains the name P which is a non-empty string whose length does not exceed N characters. The string consists only of the first K lowercase symbols of an English alphabet.
The third line contains the string of length N - length(P) + 1, consisting only of numbers zero and one. A number one in the i-th position means that an occurrence of the name P should start from i-th position of the desired word, while a zero means that there is no occurrence starting here.
第一行包含两个数 N 和 K,分别表示所求字符串的长度和字母表大小。限制条件为:1 ≤ N ≤ 100,2 ≤ K ≤ 26。
第二行包含一个非空字符串 P,其长度不超过 N 个字符。该字符串仅由英文字母表的前 K 个小写字母组成。
第三行包含一个长度为 N−length(P)+1 的字符串,该字符串仅由数字 0 和 1 组成。第 i 位上的 1 表示所求单词的第 i 位应是名字 P 的一次出现的起始位置;而 0 则表示此处不能作为 P 的一次出现的起始位置。
输出格式
Print the desired word S. If there are several answers, print any of them.
If there is no solution, then print "No solution".
输出目标单词 S。如果存在多个答案,输出任意一个即可。
如果无解,则输出 "No solution"。
输入输出样例
输入#1
5 2 aba 101
输出#1
ababa
输入#2
5 2 a 10001
输出#2
abbba
输入#3
6 2 abba 101
输出#3
No solution
输入解题思路,AI测评打分。不知道怎么写?