CF1825A.LuoTianyi and the Palindrome String

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

LuoTianyi gives you a palindrome†^{\dagger} string ss, and she wants you to find out the length of the longest non-empty subsequence‡^{\ddagger} of ss which is not a palindrome string. If there is no such subsequence, output −1-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 aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from bb. For example, strings "a", "aaa", "bab" are subsequences of string "abaab", but strings "codeforces", "bbb", "h" are not.

洛天依给你一个回文字符串 ss,她希望你找出 ss 的最长非空子序列的长度,该子序列不是回文串。如果不存在这样的子序列,则输出 −1-1。

†^{\dagger} 回文串是指正读和反读都相同的字符串。例如,字符串 "z"、"aaa"、"aba"、"abccba" 是回文串,但字符串 "codeforces"、"reality"、"ab" 不是。

‡^{\ddagger} 若字符串 aa 可通过从字符串 bb 中删除若干(可能为零个或全部)字符得到,则称 aa 是 bb 的子序列。例如,字符串 "a"、"aaa"、"bab" 都是字符串 "abaab" 的子序列,但字符串 "codeforces"、"bbb"、"h" 不是。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001 \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 ss (1≤∣s∣≤501 \le |s| \le 50) consisting of lowercase English letters — the string that LuoTianyi gives you. It's guaranteed that ss is a palindrome string.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个字符串 ss(1≤∣s∣≤501 \le |s| \le 50),由小写英文字母组成——这是 LuoTianyi 给你的字符串。保证 ss 是一个回文字符串。

输出格式

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.

对于每个测试用例,输出一个整数——最长的非空子序列的长度,该子序列不是回文字符串。如果不存在这样的子序列,则输出 −1-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 66.

In the second test case, we can only get "a" and "aa", but they are all palindrome strings, so the answer is −1-1.

在第一个测试用例中,“abcaba”是“abacaba”的一个子序列,因为我们可以删除“abacaba”的第三个字母得到“abcaba”,且“abcaba”不是一个回文字符串。可以证明,“abcaba”是“abacaba”的所有非回文子序列中最长的一个,因此答案为 66。

在第二个测试用例中,我们只能得到“a”和“aa”,但它们均为回文字符串,因此答案为 −1-1。

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

首页