From 5fc340e2416e96221f8e8b757cc9aaadecdf6b71 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 4 Apr 2020 19:17:23 +0200 Subject: Create parenting.cc --- cpp/parenting.cc | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 cpp/parenting.cc (limited to 'cpp') diff --git a/cpp/parenting.cc b/cpp/parenting.cc new file mode 100644 index 0000000..f6117d6 --- /dev/null +++ b/cpp/parenting.cc @@ -0,0 +1,80 @@ +// Google Code Jam 2020 +#include +#include +#include + +using namespace std; + +short find_free(const vector& c, const vector& j, int ii, int jj) { + // 0 = c + // 1 = j + bool skip{true}; + for(int i = ii; i < jj; ++i) { + if(!c.at(i)) { + skip = false; + break; + } + } + + if(skip) return 0; + + for(int i = ii; i < jj; ++i) { + if(!j.at(i)) { + return -1; + } + } + + return 1; +} + +bool sortpair(const pair& a, const pair& b) { + return (a.first + a.second < b.first + b.second && (a.first < a.second || b.first < b.second)); +} + +int main() { + int T; + cin >> T; + + vector> p; + for(int _ = 0; _ < T; ++_) { + int N; + cin >> N; + + p.clear(); + string s; + vector _c(24*60+1, true); + vector _j(24*60+1, true); + for(int i = 0; i < N; ++i) { + int e1, e2; + cin >> e1 >> e2; + p.push_back({e1, e2}); + } + + for(int i = 0; i < N; ++i) { + int index1 = p[i].first; + int index2 = p[i].second; + int who = find_free(_c, _j, index1, index2); + switch(who) { + case 0: + { + s += "C"; + for(int j = index1; j < index2; ++j) _c[j] = false; + break; + } + case 1: + { + s += "J"; + for(int j = index1; j < index2; ++j) _j[j] = false; + break; + } + } + if(who == -1) { + s = "IMPOSSIBLE"; + break; + } + } + cout << "Case #" << _+1 << ": " << s << endl; + } + + return 0; +} -- cgit v1.2.3-18-g5258