43042023-03-23 10:37:261478Kígyózó szavakcpp17Wrong answer 30/1004ms4436 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int h, n;
    cin>>h>>n;
    vector<vector<int>> dp(h+1, vector<int>(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/03ms1808 KiB
2Accepted0/03ms2060 KiB
3Accepted5/53ms2496 KiB
4Accepted5/53ms2508 KiB
5Accepted5/53ms2488 KiB
6Accepted5/54ms2620 KiB
7Accepted5/54ms2860 KiB
8Accepted5/54ms3080 KiB
9Wrong answer0/54ms3180 KiB
10Wrong answer0/54ms3488 KiB
11Wrong answer0/54ms3776 KiB
12Wrong answer0/54ms3976 KiB
13Wrong answer0/54ms4112 KiB
14Wrong answer0/64ms3916 KiB
15Wrong answer0/64ms4044 KiB
16Wrong answer0/64ms4012 KiB
17Wrong answer0/64ms4212 KiB
18Wrong answer0/74ms4232 KiB
19Wrong answer0/74ms4436 KiB
20Wrong answer0/74ms4356 KiB