43082023-03-23 11:08:271478Kígyózó szavakcpp17Wrong answer 30/1004ms3600 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    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];
            //dp[i][j]=min(dp[i][j],1000000000LL);
        }
    }

    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/03ms1972 KiB
2Accepted0/03ms2204 KiB
3Accepted5/53ms2408 KiB
4Accepted5/53ms2492 KiB
5Accepted5/53ms2536 KiB
6Accepted5/53ms2664 KiB
7Accepted5/54ms2908 KiB
8Accepted5/54ms2944 KiB
9Wrong answer0/54ms3384 KiB
10Wrong answer0/54ms3224 KiB
11Wrong answer0/54ms3428 KiB
12Wrong answer0/54ms3300 KiB
13Wrong answer0/54ms3412 KiB
14Wrong answer0/64ms3108 KiB
15Wrong answer0/64ms3424 KiB
16Wrong answer0/64ms3344 KiB
17Wrong answer0/64ms3356 KiB
18Wrong answer0/74ms3336 KiB
19Wrong answer0/74ms3552 KiB
20Wrong answer0/74ms3600 KiB