Ankit_132

C

Aug 13th, 2023
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define pb     push_back
  8.  
  9. int main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.     cout.tie(NULL);
  14.  
  15.     int n, m;
  16.     string s;
  17.     cin>>n>>m>>s;
  18.  
  19.     vector<int> c(n);
  20.     for(auto &e: c)
  21.         cin>>e;
  22.  
  23.     vector<vector<int>> pos(m+1);
  24.  
  25.     for(int i=0; i<n; i++)
  26.         pos[c[i]].pb(i);
  27.  
  28.     string ans(n, '.');
  29.  
  30.     for(auto e: pos)
  31.     {
  32.         for(int i=0; i<e.size(); i++)
  33.             ans[e[(i+1)%(e.size())]] = s[e[i]];
  34.     }
  35.  
  36.     cout<<ans<<"\n";
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment