AhmedAshraff

Untitled

Nov 24th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
  3. #define ll long long
  4. #define sz(s) (int)(s).size()
  5. #define all(s) (s).begin(),(s).end()
  6. using namespace std;
  7. void File();
  8. void sol();
  9. const int N=20;
  10. string ans[N]{};
  11. struct word{
  12.     int len,freq,k,subseq,sbstr;
  13.     char curr;
  14.     vector<int>fs;
  15.     word(){
  16.         k=0, subseq=1, len=0, freq=0, curr='a';
  17.         sbstr=0;
  18.         fs=vector<int>{0};
  19.     }
  20.     bool add(int nw){
  21.         if((nw && curr=='z') || (nw && len==0))return false;
  22.         len++;
  23.         if(nw){
  24.             freq=1;
  25.             curr++;
  26.             subseq*=2;
  27.             sbstr+=len;
  28.             fs.emplace_back(1);
  29.         }
  30.         else {
  31.             subseq/=(freq + 1);
  32.             freq++;
  33.             subseq*=(freq + 1);
  34.             sbstr++;
  35.             fs.back()++;
  36.         }
  37.         k= subseq - sbstr;
  38.         if(k>=N)return false;
  39.         return true;
  40.     }
  41.     string get_str(){
  42.         string st="a";
  43. //        char s='a';
  44. //        for(auto it:fs)st+=string(it,s++);
  45.         return st;
  46.     }
  47. };
  48. void pre(){
  49.     queue<word>q;
  50.     word st;
  51.     q.emplace(st);
  52.     while(!q.empty()){
  53.         auto curr=q.front();
  54.         q.pop();
  55.         if(curr.k>=N)break;
  56.         word w1=curr,w2=curr;
  57.         if(w1.add(0)) {
  58.             if (ans[w1.k].empty()) {
  59.                 ans[w1.k] = w1.get_str();
  60.             }
  61.             q.emplace(w1);
  62.         }
  63.         if(w2.add(1)){
  64.             if(ans[w2.k].empty()) {
  65.                 ans[w2.k] = w2.get_str();
  66.             }
  67.             q.emplace(w2);
  68.         }
  69.     }
  70. }
  71. int main() {
  72.     boAshraf
  73.     File();
  74.     int t = 1;
  75.     cin >> t;
  76.     pre();
  77.     while (t--) {
  78.         sol();
  79.     }
  80.     return 0;
  81. }
  82.  
  83. void sol() {
  84.     int s;
  85.     cin>>s;
  86.     cout<<ans[s]<<'\n';
  87. }
  88. ccccc
  89. void File() {
  90. #ifndef ONLINE_JUDGE
  91.     freopen("input.txt", "r", stdin);
  92.     freopen("output.txt", "w", stdout);
  93. #endif
  94. }
Advertisement
Add Comment
Please, Sign In to add comment