String Equations
Time limit1sMemory limit128 MB
Decide whether a subset of distinct short strings and their repeats can be split into two groups whose multiset union of characters is identical.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Dynamic programming, Hash map
- Solved
- No attempts yet
Problem
We all understand numeric equations such as . But what happens if we work with strings instead of numbers? What would addition and equality mean?
Given two strings and , define to be the concatenation of the two strings. Define to mean that is an anagram of ; that is, the characters of can be rearranged to form .
You are given distinct non-empty strings, each consisting of at most lowercase letters. You may also assume that at most distinct characters appear across all of the strings. Decide whether you can place some strings on the left side and some strings on the right side of an equation so that the two "sums" are "equal" under the definitions above. Each string may be used or more times on a side, but no string may appear on both sides of the equation, and each side must use at least one string.
Input
The input contains several test cases. Each test case begins with a line containing the integer (). The next lines each contain one of the strings. The input terminates with a line containing , which is not processed.
Output
For each test case, print a single line containing yes if it is possible to form such an equation, or no otherwise.