113982024-09-08 19:50:13Vkrisztian01Kígyózó szavakcpp17Wrong answer 20/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];
    }

    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
base20/100
1Accepted0/03ms360 KiB
2Accepted0/03ms488 KiB
3Accepted5/52ms360 KiB
4Accepted5/53ms360 KiB
5Accepted5/53ms504 KiB
6Accepted5/53ms360 KiB
7Wrong answer0/53ms500 KiB
8Wrong answer0/53ms360 KiB
9Wrong answer0/524ms872 KiB
10Wrong answer0/519ms744 KiB
11Wrong answer0/529ms800 KiB
12Wrong answer0/530ms1040 KiB
13Wrong answer0/557ms1512 KiB
14Wrong answer0/614ms672 KiB
15Wrong answer0/629ms996 KiB
16Wrong answer0/618ms540 KiB
17Wrong answer0/616ms616 KiB
18Wrong answer0/718ms744 KiB
19Wrong answer0/754ms1420 KiB
20Wrong answer0/720ms776 KiB