256032026-02-22 16:43:27999Kígyózó szavakcpp17Accepted 100/10039ms1628 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
#define int long long

const long long LIM = 1e18;

string s(int ch,int mxl,vector<array<int,26>> &hany, int k){
    if(mxl==0||k==1)return "";
    k--;
    if(ch==0){
        return 'b'+s(ch+1,mxl-1,hany,k);
    }
    if(ch==25){
        return 'y'+s(ch-1,mxl-1,hany,k);
    }
    if(hany[mxl][ch-1]>=k){
        char c='a'+(ch-1);
        return c+s(ch-1,mxl-1,hany,k);
    }
    char c='a'+(ch+1);
    k-=hany[mxl][ch-1];
    return c+s(ch+1,mxl-1,hany,k);

}


signed main() {
    int n,h;cin>>h>>n;
    vector<array<int,26>> dp(h+1),hany(h+1);
    for(int i = 0;i<26;i++){
        dp[1][i]=1;
        hany[1][i]=1;
    }
    for(int i = 2;i<=h;i++){
        for(int j = 0;j<26;j++){
            dp[i][j]=min(LIM,(j>0?dp[i-1][j-1]:0)+(j<25?dp[i-1][j+1]:0));
            hany[i][j]=min(LIM,hany[i-1][j]+dp[i][j]);
        }
    }
    /*for(int j = 0;j<26;j++){
        cout<<j<<": ";
        for(int i = 1;i<=h;i++){
            cout<<hany[i][j]<<", ";
        }cout<<endl;
    }*/
    while(n--){
        int k;cin>>k;
        string ans="";
        int kezdobet=0;
        for(int i = 0;i<26;i++){
            if(k<=hany[h][i]){
                kezdobet=i;
                break;
            }
            k-=hany[h][i];
        }
        ans+='a'+kezdobet;
        ans+=s(kezdobet,h-1,hany,k);
        cout<<ans<<endl;
    }
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/01ms512 KiB
2Accepted0/01ms316 KiB
3Accepted5/51ms316 KiB
4Accepted5/51ms316 KiB
5Accepted5/52ms384 KiB
6Accepted5/52ms316 KiB
7Accepted5/53ms316 KiB
8Accepted5/53ms316 KiB
9Accepted5/516ms656 KiB
10Accepted5/513ms724 KiB
11Accepted5/518ms868 KiB
12Accepted5/519ms896 KiB
13Accepted5/539ms1628 KiB
14Accepted6/68ms572 KiB
15Accepted6/618ms880 KiB
16Accepted6/613ms564 KiB
17Accepted6/610ms564 KiB
18Accepted7/712ms632 KiB
19Accepted7/739ms1556 KiB
20Accepted7/713ms792 KiB