Connection Status:
Competition Arena > CrazyCrazy
TCO19 SRM 756 · 2019-04-24 · by IH19980412 · Brute Force
Class Name: CrazyCrazy
Return Type: String
Method Name: possible
Arg Types: (string)
Problem Statement

Problem Statement

Shiki and Frederica are friends who like listening to songs together. They use a single cell phone to play the song, and each of them listens to it using one earphone.

For the purpose of this problem, a song is a string of lowercase English letters. Each letter represents one note of the song. The length of the song is always even.

Today the girls' music app became broken and something weird happened: each note of the song was only sent to one of the earphones.

Once the song was over, an even weirder thing happened: Shiki repeated the song she heard and Frederica realized that she has heard the exact same sequence of notes.

You are given a String song. Determine whether this string is consistent with the situation described above. That is, determine whether we can send each letter of song to exactly one earphone in such a way that the sequence of letters received by one girl will be exactly equal to the sequence received by the other girl.

If song can be the girls' favorite song, return "possible". Otherwise, return "impossible".

Constraints

  • N will be between 2 and 40, inclusive.
  • N will be even.
  • Length of song will be exactly N.
  • song will consist of lowercase English letters only ('a'-'z')
Examples
0)
"aabb"
Returns: "possible"

One possibility is that the characters are sent as follows: 'a' to Shiki 'a' to Frederica 'b' to Shiki 'b' to Frederica This way, each of the girls will hear the string "ab".

1)
"abba"
Returns: "impossible"
2)
"verylazyverylazy"
Returns: "possible"

One possible scenario: Shiki hears the first eight characters and Frederica hears the rest.

3)
"arqmpfvvbtltlhufznkldkurrazmgebfxeamrewn"
Returns: "impossible"
4)
"aacfcfqqsmksimkoioeertbrtbhphnpnggddjjll"
Returns: "possible"

Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CrazyCrazy with a public method string possible(string song) · 75 test cases · 2 s / 256 MB per case

Submitting as anonymous