A1313 | [COCI-2015_2016-contest5]#1 MULTIGRAM
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Pero is a passionate lover of riddles. The newest type of riddles he has come across requires the solver to check whether the given word is a multigram.
A multigram is a word that consists of concatenating two or more words that are all mutually anagrams. The first of these words is called the root of the multigram. For instance, the word bbabab is a multigram with the root bba because it consists of anagrams bba and bab.
Help Pero solve the riddle by determining whether his word is a multigram and determining its root in case it is. If there are multiple possible roots of the multigram, output the shortest.
Please note: Two words are mutually anagrams if one of them can be obtained from the other by changing the letter order.
A multigram is a word that consists of concatenating two or more words that are all mutually anagrams. The first of these words is called the root of the multigram. For instance, the word bbabab is a multigram with the root bba because it consists of anagrams bba and bab.
Help Pero solve the riddle by determining whether his word is a multigram and determining its root in case it is. If there are multiple possible roots of the multigram, output the shortest.
Please note: Two words are mutually anagrams if one of them can be obtained from the other by changing the letter order.
输入格式
The first and only line of input contains a word of length at most 100 000 lowercase English character
输出格式
If the given word is not a multigram, output −
1.
Otherwise, output the shortest root of the given word in one line.
1.
Otherwise, output the shortest root of the given word in one line.
输入输出样例
输入 #1
aaaa
输出 #1
a
输入 #2
ab
输出 #2
-1
输入 #3
bbabab
输出 #3
bba
Clarification of the first example: Notice that the word “aa” could also be the root, but “a” is shorter.
Clarification of the second example: The word is not a multigram because “a” and “b” are not mutually
anagrams.
Clarification of the second example: The word is not a multigram because “a” and “b” are not mutually
anagrams.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted