codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

766A.md (1584B)


      1 Source: https://codeforces.com/problemset/problem/766/A
      2 
      3 A. Mahmoud and Longest Uncommon Subsequence
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 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.
     30 
     31 Output
     32 
     33 If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 abcd  
     41 defgh
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 5
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 a  
     54 a
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 -1
     61 ```
     62 
     63 Note
     64 
     65 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*.