#P7478. StickSuger
StickSuger
Description
YSGH gives you a string of length . Let denote the -th character of the string . You may choose an ordered pair and then swap and . The pair is valid if and only if and the string after the swap is lexicographically greater than the original string.
For two characters , we say if and only if the ASCII code of is greater than that of .
For two strings of length , is lexicographically greater than if and only if there exists an such that , and .
If there are multiple valid solutions, output the largest ordered pair.
For two ordered pairs and , we say is smaller than if and only if .
If there is no valid solution, output -1.
It is guaranteed that contains only lowercase English letters.
Input Format
The first line contains a positive integer , representing the length of the string .
The second line contains a string .
Output Format
If there is no solution, output -1.
Otherwise, output two integers on one line, representing the largest valid ordered pair .
3
acb
1 3
6
zyxwvu
-1
14
aabbccddccbbaa
6 8
Hint
Sample Explanation #1
If you choose the ordered pair , after swapping and the string becomes abc, which is lexicographically smaller than acb, so it is invalid.
If you choose the ordered pair , after swapping and the string becomes bca, which is lexicographically greater than acb, so it is valid.
Although is also valid, it is not larger than . Therefore, the answer is .
Sample Explanation #2
It is easy to see that any ordered pair is invalid.
Constraints
This problem uses bundled testdata.
For of the testdata, , and contains only lowercase English letters.
- Subtask 1 (4 points): contains only one distinct character.
- Subtask 2 (10 points): .
- Subtask 3 (16 points): .
- Subtask 4 (25 points): .
- Subtask 5 (18 points): .
- Subtask 6 (27 points): .
Translated by ChatGPT 5
京公网安备 11011102002149号