matbensch

NAQ22 D Solution (C++)

Feb 4th, 2023
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int n,m;
  8.  
  9. int main()
  10. {
  11.     cin>>n>>m;
  12.  
  13.     vector<int> arr(m);
  14.     vector<int> perm(n);
  15.  
  16.     for(int i=0;i<m;i++){cin>>arr[i];arr[i]--;}
  17.  
  18.     for(int i=0;i<n;i++)
  19.     {
  20.         int cur = i;
  21.         for(int j=0;j<m;j++)
  22.         {
  23.             // move to the right
  24.             if(arr[j]==cur) cur++;
  25.             // move to the left
  26.             else if(arr[j]==cur-1) cur--;
  27.         }
  28.         perm[cur] = i;
  29.     }
  30.  
  31.     for(int e:perm) cout << e+1 << '\n';
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment