Naxocist

Rainbow Sort

Apr 29th, 2023
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. void solve() {
  7.     int n; cin >> n;
  8.  
  9.     vector<int> v(1e5 + 3, 0), res ;
  10.     bool ok = 1;
  11.     for(int i=1; i<=n; ++i) {
  12.         int x; cin >> x;
  13.         if(v[x] == 0) res.push_back(x), v[x] = i;
  14.         else {
  15.             if(v[x] != i-1) ok = 0;
  16.             else v[x] = i;
  17.         }
  18.     }
  19.  
  20.     if(ok) for(auto x : res) cout << x << ' ';
  21.     else cout << "IMPOSSIBLE";
  22.     cout << '\n';
  23. }
  24.  
  25. int main() {
  26.     int q; cin >> q;
  27.     for(int i=1; i<=q; ++i) {
  28.         cout << "Case #" << i << ": ";
  29.         solve();
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment