CF1560E.Polycarp and String Transformation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp has a string s . Polycarp performs the following actions until the string s is empty ( t is initially an empty string):
- he adds to the right to the string t the string s , i.e. he does t=t+s , where t+s is a concatenation of the strings t and s ;
- he selects an arbitrary letter of s and removes from s all its occurrences (the selected letter must occur in the string s at the moment of performing this action).
Polycarp performs this sequence of actions strictly in this order.
Note that after Polycarp finishes the actions, the string s will be empty and the string t will be equal to some value (that is undefined and depends on the order of removing).
E.g. consider s ="abacaba" so the actions may be performed as follows:
- t ="abacaba", the letter 'b' is selected, then s ="aacaa";
- t ="abacabaaacaa", the letter 'a' is selected, then s ="c";
- t ="abacabaaacaac", the letter 'c' is selected, then s ="" (the empty string).
You need to restore the initial value of the string s using only the final value of t and find the order of removing letters from s .
输入格式
The first line contains one integer T ( 1≤T≤104 ) — the number of test cases. Then T test cases follow.
Each test case contains one string t consisting of lowercase letters of the Latin alphabet. The length of t doesn't exceed 5⋅105 . The sum of lengths of all strings t in the test cases doesn't exceed 5⋅105 .
输出格式
For each test case output in a separate line:
- −1 , if the answer doesn't exist;
- two strings separated by spaces. The first one must contain a possible initial value of s . The second one must contain a sequence of letters — it's in what order one needs to remove letters from s to make the string t . E.g. if the string "bac" is outputted, then, first, all occurrences of the letter 'b' were deleted, then all occurrences of 'a', and then, finally, all occurrences of 'c'. If there are multiple solutions, print any one.
输入输出样例
输入#1
7 abacabaaacaac nowyouknowthat polycarppoycarppoyarppyarppyrpprppp isi everywherevrywhrvryhrvrhrvhv haaha qweqeewew
输出#1
abacaba bac -1 polycarp lcoayrp is si everywhere ewyrhv -1 -1
说明/提示
The first test case is considered in the statement.