Codeforces 1185B. Email from Polycarp Codeforces Round #568 (Div. 2)


Problem link

It should be noted that if Polycarp press a key once, it's possible to appear one, two or more letters. So, if Polycarp press a key t times, letter will appear at least t times. Also, pressing a particular key not always prints same number of letters. So the possible correct solution is followed:
For both words s and t we should group consecutive identical letters with counting of the each group size. For ex, there 4 groups in the word "aaabbcaa": [aaa,bb,c,aa]. For performance you should keep every group as the letter (char) and the group size (int).
Then, if the number of groups in word s isn't equal to the number of groups in word t, then t can not be printed during typing of s. Let's go through array with such groups and compare the i-th in the word swith the i-th in the word t. If letters in groups are different, answer is NO. If the group in s are greater than group in t, answer is NO. Answer is YES in all other cases.
Every string can be splitted into such groups by one loop. So, the total time complexity is 

A solution in c++



Post a Comment

0 Comments