A15915 | LuoTianyi and the Palindrome String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
LuoTianyi gives you a palindrome $^{\dagger}$ string $s$ , and she wants you to find out the length of the longest non-empty subsequence $^{\ddagger}$ of $s$ which is not a palindrome string. If there is no such subsequence, output $-1$ instead.
$^{\dagger}$ A palindrome is a string that reads the same backward as forward. For example, strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
$^{\ddagger}$ A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from $b$ . For example, strings "a", "aaa", "bab" are subsequences of string "abaab", but strings "codeforces", "bbb", "h" are not.
$^{\dagger}$ A palindrome is a string that reads the same backward as forward. For example, strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
$^{\ddagger}$ A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters from $b$ . For example, strings "a", "aaa", "bab" are subsequences of string "abaab", but strings "codeforces", "bbb", "h" are not.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. The description of test cases follows.
The first and the only line of each test case contains a single string $s$ ( $1 \le |s| \le 50$ ) consisting of lowercase English letters — the string that LuoTianyi gives you. It's guaranteed that $s$ is a palindrome string.
The first and the only line of each test case contains a single string $s$ ( $1 \le |s| \le 50$ ) consisting of lowercase English letters — the string that LuoTianyi gives you. It's guaranteed that $s$ is a palindrome string.
输出格式
For each test case, output a single integer — the length of the longest non-empty subsequence which is not a palindrome string. If there is no such subsequence, output $-1$ .
输入输出样例
输入 #1
4 abacaba aaa codeforcesecrofedoc lol
输出 #1
6 -1 18 2
In the first test case, "abcaba" is a subsequence of "abacaba" as we can delete the third letter of "abacaba" to get "abcaba", and "abcaba" is not a palindrome string. We can prove that "abcaba" is an example of the longest subsequences of "abacaba" that isn't palindrome, so that the answer is $6$ .
In the second test case, we can only get "a" and "aa", but they are all palindrome strings, so the answer is $-1$ .
In the second test case, we can only get "a" and "aa", but they are all palindrome strings, so the answer is $-1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted