[Solution] Smaller Codeforces Solution | Solution Codeforces
Alperen has two strings, and which are both initially equal to "a".
He will perform operations of two types on the given strings:
- — Append the string exactly times at the end of string . In other words, .
- — Append the string exactly times at the end of string . In other words, .
After each operation, determine if it is possible to rearrange the characters of and such that is lexicographically smaller than .
Note that the strings change after performing each operation and don't go back to their initial states.
Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. A formal definition is as follows: string is lexicographically smaller than string if there exists a position such that , and for all , . If no such exists, then is lexicographically smaller than if the length of is less than the length of . For example, and , where we write if is lexicographically smaller than .
The first line of the input contains an integer () — the number of test cases.
The first line of each test case contains an integer — the number of operations Alperen will perform.
Then lines follow, each containing two positive integers and (; ) and a non-empty string consisting of lowercase English letters — the type of the operation, the number of times we will append string and the string we need to append respectively.
It is guaranteed that the sum of over all test cases doesn't exceed and that the sum of lengths of all strings in the input doesn't exceed .
For each operation, output "YES", if it is possible to arrange the elements in both strings in such a way that is lexicographically smaller than and "NO" otherwise.
In the first test case, the strings are initially "a" and "a".
After the first operation the string becomes "aaa". Since "a" is already lexicographically smaller than "aaa", the answer for this operation should be "YES".
After the second operation string becomes "aaa", and since is also equal to "aaa", we can't arrange in any way such that it is lexicographically smaller than , so the answer is "NO".
After the third operation string becomes "aaaaaa" and is already lexicographically smaller than it so the answer is "YES".
After the fourth operation becomes "aaab" and there is no way to make it lexicographically smaller than "aaaaaa" so the answer is "NO".
After the fifth operation the string becomes "aaaaaaabcaabcaabca", and we can rearrange the strings to: "baaa" and "caaaaaabcaabcaabaa" so that is lexicographically smaller than , so we should answer "YES".
No comments:
Post a Comment