Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
  5.  
  6. int main() {
  7.   FASTIO;
  8.   int t;
  9.   cin >> t;
  10.   for (int i = 1; i <= t; i++) {
  11.     int n;
  12.     cin >> n;
  13.     vector<pair<int, int>> h;
  14.     for (int j = 0; j < n; j++) {
  15.       int x, y;
  16.       cin >> x >> y;
  17.       h.push_back(make_pair(x, y));
  18.     }
  19.     vector<pair<int, int>> aux = h;
  20.     sort(h.begin(), h.end());
  21.     string ans = "C";
  22.     int c = h[0].second, j = -1;
  23.     for (int k = 1; k < n; k++) {
  24.       if (h[k].first >= j) {
  25.         ans += "J";
  26.         j = h[k].second;
  27.       }
  28.       else if (h[k].first >= c) {
  29.         ans += "C";
  30.         c = h[k].second;
  31.       }
  32.       else {
  33.         ans = "IMPOSSIBLE";
  34.         break;
  35.       }
  36.     }
  37.     if (ans != "IMPOSSIBLE") {
  38.       string now = "";
  39.       for (int k = 0; k < n; k++) {
  40.         for (int z = 0; z < n; z++) {
  41.           if (h[z] == aux[k]) {
  42.             now += ans[z];
  43.             break;
  44.           }
  45.         }
  46.       }
  47.       cout << "Case #" << i << ": " << now << endl;
  48.     }
  49.     else {
  50.       cout << "Case #" << i << ": " << ans << endl;
  51.     }
  52.   }
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement