#P16455. [UOI 2026] Unique Letters
[UOI 2026] Unique Letters
题目描述
You are given two strings and , consisting of lowercase Latin letters.
You may arbitrarily permute the characters in string and arbitrarily permute the characters in string .
We define the of a string as the following process. First, an auxiliary string is empty. Then the characters of string are processed from left to right. Suppose the current character is .
- If character is not present in the current string , then character is appended to the end of string .
- If character is already present in the current string , then the suffix of string up to and including the first occurrence of character is removed from . In this case, the currently processed character is not added.
The string obtained after processing all characters will be called the result of uniquization of this string.
Determine whether it is possible to obtain strings and such that:
- is a permutation of the characters of string ;
- is a permutation of the characters of string ;
- the result of uniquization of string is equal to .
输入格式
The first line contains string .
The second line contains string .
Both strings consist only of lowercase Latin letters.
输出格式
If it is impossible to obtain the required strings and , output .
Otherwise, output . Then output two strings and such that:
- is a permutation of the characters of string ;
- is a permutation of the characters of string ;
- the result of uniquization of string is equal to .
bbcdfe
fe
YES
bcdbef
ef
bbfcbbd
f
YES
bcdbfbb
f
cgbfedc
gfbc
NO
提示
For the first sample:
We permute string as , and string as .
Construct string :
- after character , we have ;
- after character , we have ;
- after character , we have ;
- after character , the letter is already present in string , so we remove the suffix up to and including the first occurrence of . After that, becomes an empty string;
- after character , we have ;
- after character , we have .
At the fourth step, letters and are also removed from string , not only letter .
The resulting string is equal to the permuted string , so an answer exists.
For the second sample:
We permute string as , and leave string as .
Construct string :
- after character , we have ;
- after character , we have ;
- after character , we have ;
- after character , the letter is already present in string , so we remove the suffix up to and including the first occurrence of . After that, becomes an empty string;
- after character , we have ;
- after character , we have ;
- after character , the letter is already present in string , so we remove the suffix up to and including the first occurrence of . After that, .
At the fourth step, letters and are also removed from string , not only letter .
The resulting string is equal to the permuted string , so an answer exists.
In the third sample, it can be proved that for no permutation of string will the result of uniquization be a permutation of string .
Scoring
- ( points): ;
- ( points): can be obtained from by permuting letters;
- ( points): all letters in are distinct;
- ( points): only one letter in string appears more than once;
- ( points): ;
- ( points): ;
- ( points): no additional constraints.