#P16210. [ECUSTPC 2025] 时间谜题
[ECUSTPC 2025] 时间谜题
Problem Description
Maddy’s digital watch was smashed. Surprisingly, the digits on it flew out and fell onto the ground.
Now she picked up two numbers from the ground. Please help her use these two numbers to form a new 24-hour time , or tell her that it is impossible.
The required 24-hour time is a string in the format HH:MM, and it must satisfy the following requirements:
- HH and MM are non-negative integers with at most two digits. If a number has only one digit, a leading should be added.
- The range of HH is , and the range of MM is .
- HH, MM, and the two given numbers must correspond one-to-one without omission or duplication. Note that you may swap the order of the two given numbers.
Input Format
The first line contains an integer (), representing the number of test cases.
For each test case, the only line contains two integers and (), representing the two numbers Maddy picked.
Output Format
For each test case, if you can form a 24-hour time using the given two numbers, output one line containing a string , representing the time you constructed. If there are multiple valid answers, you may output any one of them.
Otherwise, output one line containing an integer .
5
9 41
9 61
50 9
0 6
25 35
09:41
-1
09:50
00:06
-1
Hint
Sample 1 Explanation
For the 1st sample case, we can see that:
- and are non-negative integers with at most two digits, and a leading is added for the one-digit number.
- and satisfy the corresponding range limits.
- and correspond one-to-one with the given and without omission or duplication.
Note that is not a valid answer because it does not satisfy the corresponding range limits.
For the 2nd sample case, it is easy to see that no matter how you swap the order, you cannot form a valid 24-hour time.
Translated by ChatGPT 5