-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path2020-QR-parenting-partnering-returns.cpp
54 lines (46 loc) · 1.16 KB
/
2020-QR-parenting-partnering-returns.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
greedy
difficulty: easy
date: 04/Apr/2020
by: @brpapa
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Ta {
int s, e, i;
Ta() {}
Ta(int s, int e, int i) : s(s), e(e), i(i) {}
bool operator<(const Ta &p) const {
return s < p.s;
}
};
int main() {
int t = 1, T; cin >> T;
while (T--) {
int N; cin >> N;
vector<Ta> A(N);
for (int i = 0; i < N; i++) cin >> A[i].s >> A[i].e, A[i].i = i;
sort(A.begin(), A.end());
bool hasSolution = true;
vector<char> sortedSolution(N);
int eLastC = 0, eLastJ = 0;
for (int i = 0; i < N && hasSolution; i++) {
if (A[i].s >= eLastC) sortedSolution[i] = 'C', eLastC = A[i].e;
else if (A[i].s >= eLastJ) sortedSolution[i] = 'J', eLastJ = A[i].e;
else hasSolution = false;
}
cout << "Case #" << (t++) << ": ";
if (!hasSolution) {
cout << "IMPOSSIBLE" << endl;
}
else {
vector<char> ans(N);
for (int i = 0; i < N; i++) ans[A[i].i] = sortedSolution[i];
for (char a : ans) cout << a;
cout << endl;
}
}
return 0;
}