ash_sinha

Untitled

Sep 8th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace __gnu_pbds;
  4. using namespace std;
  5.  
  6. #define ff first
  7. #define ss second
  8. #define int long long
  9. #define pb push_back
  10. #define mp make_pair
  11. #define pii pair<int,int>
  12. #define vi vector<int>
  13. #define mii map<int,int>
  14. #define pqb priority_queue<int>
  15. #define pqs priority_queue<int,vi,greater<int> >
  16. #define setbits(x) __builtin_popcountll(x)
  17. #define zrobits(x) __builtin_ctzll(x)
  18. #define mod 1000000007
  19. #define inf 1e18
  20. #define ps(x,y) fixed<<setprecision(y)<<x
  21. #define mk(arr,n,type) type *arr=new type[n];
  22. #define w(x) int x; cin>>x; while(x--)
  23. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  24. #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
  25.  
  26. int32_t main()
  27. {
  28. fastio;
  29. int n;
  30. string s;
  31. cin>>s;n=s.length();
  32. if(n==1){cout<<"NO"<<endl;}
  33. int p=2,mx=1; char ch='a';
  34. vi hash(50,0);
  35. for(int i=0;i<n;i++) {
  36. hash[s[i]-'a']++;
  37. if(mx<=hash[s[i]]-'a'){
  38. mx=hash[s[i]-'a'];
  39. ch=s[i];
  40. }
  41. }
  42. if(mx<(n/p)){cout<<"NO"<<endl;return 0;}
  43. string ans(n,'a');
  44. for(int i=p;i<=n;i+=p) {ans[i-1]=ch;hash[ch-'a']--;}
  45. int j=0;
  46. for(int i=1;i<=n;i++)
  47. {
  48. if(i%p==0) continue;
  49. while(j<26 && hash[j]==0) j++;
  50. hash[j]--;
  51. char ch='a'+j;
  52. ans[i-1]=ch;
  53. }
  54. cout<<"YES"<<endl;
  55. cout<<ans<<endl;
  56.  
  57.  
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment