#P13050. [GCJ 2020 Qualification] Parenting Partnering Returns
[GCJ 2020 Qualification] Parenting Partnering Returns
题目描述
Cameron and Jamie's kid is almost 3 years old! However, even though the child is more independent now, scheduling kid activities and domestic necessities is still a challenge for the couple.
Cameron and Jamie have a list of activities to take care of during the day. Each activity happens during a specified interval during the day. They need to assign each activity to one of them, so that neither of them is responsible for two activities that overlap. An activity that ends at time is not considered to overlap with another activity that starts at time .
For example, suppose that Jamie and Cameron need to cover 3 activities: one running from 18:00 to 20:00, another from 19:00 to 21:00 and another from 22:00 to 23:00. One possibility would be for Jamie to cover the activity running from 19:00 to 21:00, with Cameron covering the other two. Another valid schedule would be for Cameron to cover the activity from 18:00 to 20:00 and Jamie to cover the other two. Notice that the first two activities overlap in the time between 19:00 and 20:00, so it is impossible to assign both of those activities to the same partner.
Given the starting and ending times of each activity, find any schedule that does not require the same person to cover overlapping activities, or say that it is impossible.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing a single integer , the number of activities to assign. Then, more lines follow. The -th of these lines (counting starting from 1) contains two integers and . The -th activity starts exactly minutes after midnight and ends exactly minutes after midnight.
输出格式
For each test case, output one line containing Case #x: y
, where is the test case number (starting from 1) and is IMPOSSIBLE if there is no valid schedule according to the above rules, or a string of exactly characters otherwise. The -th character in must be if the -th activity is assigned to Cameron in your proposed schedule, and if it is assigned to Jamie.
If there are multiple solutions, you may output any one of them.
4
3
360 480
420 540
600 660
3
0 1440
1 3
2 4
5
99 150
1 100
100 301
2 5
150 250
2
0 720
720 1440
Case #1: CJC
Case #2: IMPOSSIBLE
Case #3: JCCJJ
Case #4: CC
提示
Sample Explanation
Sample Case #1 is the one described in the problem statement. As mentioned above, there are other valid solutions, like JCJ
and JCC
.
In Sample Case #2, all three activities overlap with each other. Assigning them all would mean someone would end up with at least two overlapping activities, so there is no valid schedule.
In Sample Case #3, notice that Cameron ends an activity and starts another one at minute 100 .
In Sample Case #4, any schedule would be valid. Specifically, it is OK for one partner to do all activities.
Limits
- .
- $0 \leq \mathbf{S}_{\mathbf{i}}<\mathbf{E}_{\mathbf{i}} \leq 24 \times 60$.
Test set 1 (7 Pts, Visible Verdict)
- .
Test set 2 (12 Pts, Visible Verdict)
- .