A9111 | Banana
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
输入格式
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$ ).
输出格式
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.
输入输出样例
输入 #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".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted