#P5595. Constructing the Scores
Constructing the Scores
Constructing the Scores
In a singing competition, the final champion is determined by the number of likes each contestant receives. After the final round, the two contestants, X and Y, have their like counts fixed. To add suspense to the results announcement, the host reveals the outcome by performing a digit‐by‐digit comparison between the two like counts, starting from the least significant digit and progressively revealing one more digit on the left.
At each step, the revealed portion (which is the suffix of the full number) is compared. If the number formed by the digits of contestant X is greater than that of contestant Y, we denote the result with an X
; if it is less, we denote it with a Y
; and if they are equal, we denote it with a Z
.
For example, consider the following two cases:
- If X's like count is 37 and Y's is 28, then:
- Revealing the last digit: 7 vs 8 yields Y (since 7 < 8).
- Revealing both digits: 37 vs 28 yields X (since 37 > 28).
The final revealed string (recording the comparisons from the full number to the last digit) isXY
. - If X's like count is 137 and Y's is 47 (padded as 047 to make the number of digits equal), then:
- Revealing all three digits: 137 vs 047 gives X.
- Revealing the last two digits: 37 vs 47 gives Y.
- Revealing only the last digit: 7 vs 7 gives Z.
The final string isXYZ
.
Your task is: given the final comparison string s
(consisting only of the characters X
, Y
, and Z
), construct one possible pair of like counts for X and Y such that, when they are compared digit‐by‐digit (from the full number down to the last digit), the sequence of temporary leaders exactly matches s
. The numbers must be printed with leading zeros so that both have exactly n digits, where n is the length of s
.
If no valid pair exists, output -1
.
inputFormat
The input consists of a single line containing a non-empty string s
composed solely of the characters X
, Y
, and Z
.
outputFormat
If a valid assignment exists, output the two like counts (for contestants X and Y) on one line separated by a single space. Both numbers must have exactly n digits (possibly with leading zeros), where n is the length of the input string. If no valid pair exists, output -1
.
sample
XY
10 01