Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. bool available(int S, int E, vector<vector<int>> tasks) {  
  7.     if(tasks.size()==0) return true;
  8.     else {
  9.         for(int i=0; i<tasks.size(); i++) {
  10.             if((S>=tasks[i][0] && S<tasks[i][1]) || (E>tasks[i][0] && E<=tasks[i][1]) || (S<=tasks[i][0] && E>=tasks[i][1])) return false;
  11.         }
  12.         return true;
  13.     }
  14. }
  15.  
  16. void assignTask(int S, int E, vector<vector<int>> &tasks) {
  17.     if(0<=S && S<=E && E<=1440) {
  18.         tasks.push_back({S, E});
  19.     }
  20. }
  21.  
  22.  
  23. void solve() {
  24.     int N;
  25.     cin>>N;
  26.  
  27.     vector<vector<int>> JTasks, CTasks, time;
  28.     // scheduling time
  29.     for(int i=0; i<N; i++) {
  30.         int S,E;
  31.         cin>>S>>E;
  32.         if(0<=S && S<=E && E<= 1440) {
  33.             time.push_back({S, E});
  34.         }
  35.     }
  36.     // assign tasks
  37.     bool possible=true;
  38.     string str="";
  39.     for(int i=0; i<N; i++) {
  40.         int S=time[i][0];
  41.         int E=time[i][1];
  42.         if(available(S,E,CTasks)) {
  43.             assignTask(S,E,CTasks);
  44.             char c='C';
  45.             str.push_back(c);
  46.             continue;
  47.         } else if(available(S,E,JTasks)) {
  48.             assignTask(S,E,JTasks);
  49.             char j='J';
  50.             str.push_back(j);
  51.             continue;
  52.         } else {
  53.             possible=false;
  54.             break;
  55.         }
  56.     }
  57.     if(possible) cout<<str;
  58.     else cout<<"IMPOSSIBLE";
  59.     cout<<"\n";
  60. }
  61.  
  62. int main() {
  63.     ios::sync_with_stdio(0);
  64.     cin.tie(0);
  65.  
  66.     int T, i=1;
  67.     cin>>T;
  68.     while(T--) {
  69.         cout<<"Case #"<<i<<": ";
  70.         solve();
  71.         i++;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement