Advertisement
mickypinata

SMMR-T020: Toilet

Jun 18th, 2021
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. using namespace std;
  5.  
  6. vector<bool> toilet;
  7. vector<int> history;
  8. list<int> line;
  9. list<int>::iterator itr;
  10. int np, nt, x;
  11. char cmd;
  12. bool found;
  13.  
  14. void PrintVector(vector<int> &history, int sz){
  15.     for(int i = 1; i <= sz; ++i){
  16.         cout << history[i] << " ";
  17.     }
  18.     cout << "\n";
  19. }
  20.  
  21. void PrintList(list<int> &line){
  22.     for(auto x : line){
  23.         cout << x << " ";
  24.     }
  25.     cout << "\n";
  26. }
  27.  
  28. int main(){
  29.  
  30.     scanf("%d", &np);
  31.     scanf("%d", &nt);
  32.     history.assign(np + 1, -1);
  33.     toilet.assign(nt + 1, false);
  34.     for(int i = 1; i <= 2 * np; ++i){
  35.         scanf(" %c %d", &cmd, &x);
  36.         if(cmd == '1'){
  37.             found = false;
  38.             for(int j = 1; j <= nt; ++j){
  39.                 if(toilet[j] == false){
  40.                     toilet[j] = true;
  41.                     history[x] = j;
  42.                     found = true;
  43.                     break;
  44.                 }
  45.             }
  46.             if(!found){
  47.                 line.push_back(x);
  48.             }
  49.         } else if(cmd == '2'){
  50.             if(history[x] == -1){ /// In Line
  51.                 history[x] = 0;
  52.             } else {
  53.                 while(!line.empty()){
  54.                     if(history[line.front()] == 0){
  55.                         line.erase(line.begin());
  56.                     } else {
  57.                         break;
  58.                     }
  59.                 }
  60.                 if(!line.empty()){
  61.                     history[line.front()] = history[x];
  62.                     line.erase(line.begin());
  63.                 } else {
  64.                     toilet[history[x]] = false;
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     for(int i = 1; i <= np; ++i){
  70.         cout << history[i] << "\n";
  71.     }
  72.  
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement