Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define boAshraf ios_base::sync_with_stdio(false); cin.tie(NULL);
- #define ll long long
- #define sz(s) (int)(s).size()
- #define all(s) (s).begin(),(s).end()
- using namespace std;
- void File();
- void sol();
- const int N=20;
- string ans[N]{};
- struct word{
- int len,freq,k,subseq,sbstr;
- char curr;
- vector<int>fs;
- word(){
- k=0, subseq=1, len=0, freq=0, curr='a';
- sbstr=0;
- fs=vector<int>{0};
- }
- bool add(int nw){
- if((nw && curr=='z') || (nw && len==0))return false;
- len++;
- if(nw){
- freq=1;
- curr++;
- subseq*=2;
- sbstr+=len;
- fs.emplace_back(1);
- }
- else {
- subseq/=(freq + 1);
- freq++;
- subseq*=(freq + 1);
- sbstr++;
- fs.back()++;
- }
- k= subseq - sbstr;
- if(k>=N)return false;
- return true;
- }
- string get_str(){
- string st="a";
- // char s='a';
- // for(auto it:fs)st+=string(it,s++);
- return st;
- }
- };
- void pre(){
- queue<word>q;
- word st;
- q.emplace(st);
- while(!q.empty()){
- auto curr=q.front();
- q.pop();
- if(curr.k>=N)break;
- word w1=curr,w2=curr;
- if(w1.add(0)) {
- if (ans[w1.k].empty()) {
- ans[w1.k] = w1.get_str();
- }
- q.emplace(w1);
- }
- if(w2.add(1)){
- if(ans[w2.k].empty()) {
- ans[w2.k] = w2.get_str();
- }
- q.emplace(w2);
- }
- }
- }
- int main() {
- boAshraf
- File();
- int t = 1;
- cin >> t;
- pre();
- while (t--) {
- sol();
- }
- return 0;
- }
- void sol() {
- int s;
- cin>>s;
- cout<<ans[s]<<'\n';
- }
- ccccc
- void File() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment