43052023-03-23 10:39:011478Kígyózó szavakcpp17Wrong answer 30/1004ms4504 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int h, n;
    cin>>h>>n;
    vector<vector<long long>> dp(h+1, vector<long long>(27));
    //vector<int> tas

    for(int i=1; i<=26; i++){
        dp[1][i] = 1;
    }

    for(int i=2; i<=h; i++){
        for(int j = 1; j<=26; j++){
            if(j>1) dp[i][j] += dp[i-1][j-1];
            if(j<26) dp[i][j] += dp[i-1][j+1];
        }
    }

    for(int i=2; i<=h; i++){
        for(int j=1; j<=26; j++){
            dp[i][j] += dp[i-1][j];
        }
    }

    for(int i=1; i<=n; i++){
        string sol;
        int k, g = h;
        cin>>k;
        int ind = 1;
        while(k-dp[g][ind] > 0){
            k -= dp[g][ind];
            ++ind;
        }
        sol +='a' + ind - 1;
        //cout<<sol<<" ";
        //cout<<k<<": ";
        bool ok = 0;
        while(1){
            k--;
            g--;
            if(k <= 0) {
                break;
            }
            if(ind > 1 && ind < 26){
                if(k-dp[g][ind-1] > 0) {
                sol+='a'+ind;
                //cout<<sol<<" ";

                k -= dp[g][ind-1];
                //cout<<k<<endl;
                ind++;
                }
                else{
                    sol+='a'+ind-2;
                    //cout<<sol<<" "<<k<<endl;
                    ind--;
                }
            }
            else if(ind == 1){
                sol+='b';
                ind++;
            }
            else if(ind == 26){
                sol+='y';
                ind--;
            }
        }
        cout<<sol<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/100
1Accepted0/03ms1812 KiB
2Accepted0/03ms2056 KiB
3Accepted5/53ms2300 KiB
4Accepted5/53ms2460 KiB
5Accepted5/53ms2672 KiB
6Accepted5/53ms2756 KiB
7Accepted5/54ms2752 KiB
8Accepted5/54ms2844 KiB
9Wrong answer0/54ms3292 KiB
10Wrong answer0/54ms3112 KiB
11Wrong answer0/54ms3412 KiB
12Wrong answer0/54ms3368 KiB
13Wrong answer0/54ms3604 KiB
14Wrong answer0/64ms3300 KiB
15Wrong answer0/64ms3528 KiB
16Wrong answer0/64ms3744 KiB
17Wrong answer0/64ms3940 KiB
18Wrong answer0/74ms3908 KiB
19Wrong answer0/74ms4504 KiB
20Wrong answer0/74ms4444 KiB