-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathC.cpp
More file actions
executable file
·45 lines (39 loc) · 862 Bytes
/
C.cpp
File metadata and controls
executable file
·45 lines (39 loc) · 862 Bytes
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string parenting_partnering_returns(int N, vector<int>& S, vector<int>& E) {
string s(N, '?');
vector<int> p(2);
vector<vector<int>> a(N);
vector<char> c = {'C', 'J'};
for (int i = 0; i < N; i++)
a[i] = {S[i], E[i], i};
sort(a.begin(), a.end());
for (vector<int>& act: a) {
bool found = false;
for (int i = 0; i < p.size() && !found; i++)
if (p[i] <= act[0]) {
s[act[2]] = c[i];
p[i] = act[1];
found = true;
}
if (!found)
return "IMPOSSIBLE";
}
return s;
}
int main() {
int T;
cin >> T;
for (int x = 1; x <= T; x++) {
int N;
cin >> N;
vector<int> S(N), E(N);
for (int i = 0; i < N; i++)
cin >> S[i] >> E[i];
cout << "Case #" << x << ": " << parenting_partnering_returns(N, S, E) << endl;
}
return 0;
}