#abc284f. F - ABCBAC
F - ABCBAC
Score : points
问题描述
对于一个长度为 的字符串 和一个整数 ,我们定义字符串 如下:
- 字符串 的前 个字符,
- 字符串 的反转,
- 字符串 的最后 个字符,
按照这个顺序拼接而成。例如,如果 abc
并且 ,那么有 abcbac
。
现给定一个长度为 的字符串 。找出一对字符串 (长度为 )和整数 ,使得 。若不存在这样的字符串 和整数 的组合,请报告这一事实。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For a string of length and an integer , let us define the string as the concatenation of:
- the first characters of ,
- the reversal of , and
- the last characters of ,
in this order. For instance, if abc
and , we have abcbac
.
You are given a string of length . Find a pair of a string of length and an integer such that . If no such pair of and exists, report that fact.
Constraints
- is an integer.
- is a string of length consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
If no pair of and satisfies the condition, print -1
. Otherwise, print and , separated by a newline. If multiple pairs of and satisfy the condition, you may print any of them.
Sample Input 1
3
abcbac
Sample Output 1
abc
2
As mentioned in the problem statement, if abc
and , we have abcbac
, which equals , so you should print abc
and .
Sample Input 2
4
abababab
Sample Output 2
abab
1
abab
and also satisfy the condition.
Sample Input 3
3
agccga
Sample Output 3
cga
0
agc
and also satisfy the condition.
Sample Input 4
4
atcodeer
Sample Output 4
-1
If no pair of and satisfies the condition, print -1
.
update @ 2024/3/10 11:54:13