jakaria_hossain

Codeforce - swap adjacent element

Oct 21st, 2018
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. vector<int>sorted,unsorted;
  5. int main()
  6. {
  7. int n;
  8. scanf("%d",&n);
  9. int i,x,pos;
  10. for(i=0; i<n; i++)
  11. {
  12. scanf("%d",&x);
  13. sorted.pb(x);
  14. unsorted.pb(x);
  15. }
  16. sort(sorted.begin(),sorted.end());
  17. string s;
  18. cin>>s;
  19. for(i=0; i<n-1; i++)
  20. {
  21. if(s[i]=='1')
  22. {
  23. pos=i;
  24. while(s[i]=='1')
  25. i++;
  26. sort(unsorted.begin()+pos,unsorted.begin()+i+1);
  27. }
  28. }
  29. if(sorted==unsorted)
  30. printf("YES\n");
  31. else
  32. printf("NO\n");
  33. return 0;
  34. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×