CF766A.Mahmoud and Longest Uncommon Subsequence
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.
A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.
在马哈茂德和埃哈卜为国际信息学奥林匹克竞赛(IOI)备赛期间,他们遇到了一道名为“最长公共子序列”的题目。他们成功解决了该题,随后埃哈卜向马哈茂德提出了另一道挑战题。
给定两个字符串 a 和 b,求它们的最长非公共子序列的长度,即:满足“是其中某一个字符串的子序列,但不是另一个字符串的子序列”的最长字符串的长度。
某个字符串的子序列,是指该字符串中按相同顺序出现的一组字符所构成的序列;这些字符在原字符串中的出现位置不必连续。例如,字符串 "ac"、"bc"、"abc" 和 "a" 都是 "abc" 的子序列,而 "abbc" 和 "acb" 则不是。空字符串是任意字符串的子序列;任意字符串都是其自身的子序列。
输入格式
The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
第一行包含字符串 a,第二行包含字符串 b。这两个字符串均非空,且仅由小写英文字母组成。每个字符串的长度均不超过 105 个字符。
输出格式
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
如果不存在不公共子序列,则输出 -1。否则,输出字符串 a 和 b 的最长不公共子序列的长度。
输入输出样例
输入#1
abcd defgh
输出#1
5
输入#2
a a
输出#2
-1
说明/提示
In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
在第一个例子中:你可以从字符串 b 中选择 "defgh",因为它是字符串 b 的最长子序列,且不作为子序列出现在字符串 a 中。
输入解题思路,AI测评打分。不知道怎么写?