fork(8) download
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <string>
  6. #include <algorithm>
  7. #include <utility>
  8. #include <queue>
  9. #include <stack>
  10. #include <string>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <map>
  14. #include <vector>
  15. #include <array>
  16. #include <set>
  17. #include <climits>
  18. #include <sstream>
  19. #include <iomanip>
  20. #include <cassert>
  21. #include <bitset>
  22. #include <numeric>
  23. using namespace std;
  24. using namespace __gnu_pbds;
  25. typedef tree< // find_by_order & order_of_key
  26. int ,
  27. null_type ,
  28. less<int> ,
  29. rb_tree_tag ,
  30. tree_order_statistics_node_update
  31. > new_set;
  32. #define MOD 1000000007
  33. #define MAXN 1002
  34. bool compare(pair<int,int>&i ,pair<int,int>&j){
  35. return (i.second<j.second);
  36. }
  37. int main(void){
  38. #ifdef HELL_JUDGE
  39. freopen("input","r",stdin);
  40. freopen("output","w",stdout);
  41. freopen("error","w",stderr);
  42. #endif
  43. int t; scanf("%d",&t);
  44. for(int tt=1;tt<=t;++tt){
  45. array<int,MAXN>diff_array;
  46. fill(diff_array.begin() , diff_array.end() , 0);
  47. array<pair<int,int>,MAXN>activity;
  48. array<pair<int,int>,MAXN>temp_activity;
  49. map<pair<int,int> , char>answer;
  50. printf("Case #%d: ",tt);
  51. int n;scanf("%d",&n);
  52. for(int i=0;i<n;++i){
  53. int &u = activity[i].first;
  54. int &v = activity[i].second;
  55. scanf("%d%d",&u,&v);
  56. diff_array[u]++;
  57. diff_array[v+1]--;
  58. temp_activity[i] = activity[i];
  59. }
  60. for(int i=1;i<=n;++i){
  61. diff_array[i]+=diff_array[i-1];
  62. }
  63. if(any_of(diff_array.begin() , diff_array.begin()+n,[](int &i){return i>2;})){
  64. puts("IMPOSSIBLE");
  65. continue;
  66. }else{
  67. // let's create two pointer and keep them move , when current work's starting is less then or equal to
  68. // the any of pointer we will fix it to the end of that activity :- that means that activity is done by that person
  69. int c{} , j{};
  70. sort(activity.begin(),activity.begin()+n , compare);
  71. for(int i=0;i<n;++i){
  72. cerr<<activity[i].first<<' '<<activity[i].second<<'\n';
  73. if(c<=activity[i].first){
  74. answer[activity[i]] = 'C';
  75. c = activity[i].second;
  76. }else if(j<=activity[i].first){
  77. answer[activity[i]] = 'J';
  78. j = activity[i].second;
  79. }else{
  80. puts("Something is Wrong");
  81. return 0;
  82. }
  83. }
  84. for(int i=0;i<n;++i){
  85. cout<<answer[temp_activity[i]];
  86. }
  87. puts("");
  88. }
  89. }
  90. return 0;
  91. }
Success #stdin #stdout 0s 4148KB
stdin
Standard input is empty
stdout
Standard output is empty