#P16210. [ECUSTPC 2025] 时间谜题

    ID: 18225 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度入门 上传者: 标签>模拟2025Special Judge高校校赛

[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 TimeTime, 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 00 should be added.
  • The range of HH is 0HH230 \le HH \le 23, and the range of MM is 0MM590 \le MM \le 59.
  • 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 TT (1T1041 \le T \le 10^4), representing the number of test cases.
For each test case, the only line contains two integers aa and bb (0a,b990 \le a, b \le 99), 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 TimeTime, 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 1-1.

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:

  • 0909 and 4141 are non-negative integers with at most two digits, and a leading 00 is added for the one-digit number.
  • 0909 and 4141 satisfy the corresponding range limits.
  • 0909 and 4141 correspond one-to-one with the given 99 and 4141 without omission or duplication.

Note that 41:0941:09 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