CF335A.Banana

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Piegirl wants to create a string s using stickers. She may buy as many sheets of stickers as she wants, and may specify any string of length n for the sheets, but all the sheets must be identical, so the string is the same for all sheets. Once she attains the sheets of stickers, she will take some of the stickers from the sheets and arrange (in any order) them to form s. Determine the minimum number of sheets she has to buy, and provide a string describing a possible sheet of stickers she should buy.

Piegirl 正在为一个项目购买贴纸。贴纸以整张的形式出售,每张贴纸 sheet 恰好包含 nn 张贴纸。每张贴纸上面恰好印有一个字符,因此一张贴纸 sheet 可以用一个长度为 nn 的字符串来描述。Piegirl 希望用贴纸拼出字符串 ss。她可以购买任意数量的贴纸 sheet,并且可以自由指定每张 sheet 所对应的长度为 nn 的字符串;但所有购买的 sheet 必须完全相同(即所有 sheet 均由同一个字符串描述)。在获得这些 sheet 后,她将从这些 sheet 中取出若干张贴纸,并以任意顺序排列,从而组成字符串 ss。请确定她所需购买的最少 sheet 数量,并给出一种可行的、对应于该最小数量的 sheet 字符串。

输入格式

The first line contains string s (1 ≤ |s| ≤ 1000), consisting of lowercase English characters only. The second line contains an integer n (1 ≤ n ≤ 1000).

第一行包含字符串 ss(1 ≤ ∣s∣ ≤ 10001 \leq |s| \leq 1000),仅由小写英文字母组成。第二行包含一个整数 nn(1 ≤ n ≤ 10001 \leq n \leq 1000)。

输出格式

On the first line, print the minimum number of sheets Piegirl has to buy. On the second line, print a string consisting of n lower case English characters. This string should describe a sheet of stickers that Piegirl can buy in order to minimize the number of sheets. If Piegirl cannot possibly form the string s, print instead a single line with the number -1.

第一行输出 Piegirl 需要购买的贴纸页数的最小值。
第二行输出一个由 n 个小写英文字母组成的字符串,该字符串描述了 Piegirl 可以购买的一张贴纸页,使得所购贴纸页总数最少。如果 Piegirl 根本无法拼出字符串 s,则仅输出一行数字 -1。

输入输出样例

  • 输入#1

    banana
    4

    输出#1

    2
    baan
  • 输入#2

    banana
    3

    输出#2

    3
    nab
  • 输入#3

    banana
    2

    输出#3

    -1

说明/提示

In the second example, Piegirl can order 3 sheets of stickers with the characters "nab". She can take characters "nab" from the first sheet, "na" from the second, and "a" from the third, and arrange them to from "banana".

在第二个例子中,Piegirl 可以订购 3 张贴纸,上面分别印有字符 “nab”。她可以从第一张贴纸上取字符 “nab”,从第二张贴纸上取字符 “na”,从第三张贴纸上取字符 “a”,然后将它们排列组合成 “banana”。

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

首页