113992024-09-08 19:53:52Vkrisztian01Kígyózó szavakcpp17Accepted 100/10057ms1512 KiB
#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
const ll m = 1e9;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr);

    ll h,n;
    cin>>h>>n;

    vector<vector<ll> > dp(h + 1,vector<ll>(26,0));

    for(int j = 0; j<26; j++)
        dp[0][j] = 1;

    for(int i=1; i< h; i++)
    {
        dp[i][0] = dp[i-1][1] + 1;

        for(int j=1;j<25;j++)
        {
            dp[i][j] = min((ll)INT_MAX,dp[i-1][j-1] + dp[i-1][j+1] + 1);
        }

        dp[i][25] = dp[i-1][24] + 1;
    }

    while(n--)
    {
        ll k;
        cin>>k;

        string ans = "";

        int letter = 0;

        while(dp[h - 1][letter] < k)
        {
            k -= dp[h - 1][letter];
            letter++;
        }

        ans += 'a' + letter;

        for(int i = h - 2; i>=0; i--)
        {
            if(k == 1) break;

            k--;

            vector<int> options;
            if(0 < letter)
                options.push_back(letter - 1);
            if(letter < 25)
                options.push_back(letter + 1);

            for(int j: options)
            {
                if(dp[i][j] < k)
                {
                    k -= dp[i][j];
                }
                else
                {
                    ans += 'a' + j;
                    letter = j;
                    break;
                }
            }
        }

        cout<<ans<<"\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms360 KiB
2Accepted0/02ms360 KiB
3Accepted5/53ms504 KiB
4Accepted5/53ms400 KiB
5Accepted5/53ms360 KiB
6Accepted5/53ms504 KiB
7Accepted5/53ms376 KiB
8Accepted5/53ms360 KiB
9Accepted5/524ms872 KiB
10Accepted5/519ms744 KiB
11Accepted5/529ms872 KiB
12Accepted5/530ms828 KiB
13Accepted5/557ms1412 KiB
14Accepted6/614ms488 KiB
15Accepted6/629ms1016 KiB
16Accepted6/618ms744 KiB
17Accepted6/617ms632 KiB
18Accepted7/717ms656 KiB
19Accepted7/754ms1512 KiB
20Accepted7/720ms744 KiB