Guest User

Untitled

a guest
Apr 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct triple{
  5.     int first, second, third;
  6. };
  7.  
  8. bool cmp(triple &t1, triple &t2){
  9.     return t1.first < t2.first;
  10. }
  11.  
  12. int main()
  13. {
  14. // #ifndef ONLINE_JUDGE
  15. //     freopen("ip.txt", "r", stdin);
  16. //     freopen("op.txt", "w", stdout);
  17. // #endif
  18.     int t; cin >> t;
  19.     for(int test = 1; test <= t; ++test){
  20.         string ans = "IMPOSSIBLE", s;
  21.         int n, flag = 0;
  22.         cin >> n;
  23.         vector<triple> acts(n);
  24.         for(int i = 0; i < n; i++){
  25.             s += '0';
  26.             cin >> acts[i].first >> acts[i].second;
  27.             acts[i].third = i;
  28.         }
  29.        
  30.         sort(acts.begin(), acts.end(), cmp);
  31.  
  32.         bool c = 0, f = 0;
  33.         int fends = -1, cends = -1;
  34.         for(int i = 0; i < n; ++i){
  35.             if(acts[i].first >= fends){
  36.                 f = 0;
  37.             }
  38.             if(acts[i].first >= cends){
  39.                 c = 0;
  40.             }
  41.             if(!f){
  42.                 f = 1;
  43.                 s[acts[i].third] = 'J';
  44.                 fends = acts[i].second;
  45.             }else if(!c){
  46.                 c = 1;
  47.                 s[acts[i].third] = 'C';
  48.                 cends = acts[i].second;
  49.             }else{
  50.                 flag = 1;
  51.                 break;
  52.             }
  53.         }
  54.         cout << "Case #" << test << ": " << (flag ? ans : s) << endl;
  55.     }
  56. }
Add Comment
Please, Sign In to add comment