97182024-03-03 16:08:32csdavidKígyózó szavakcpp17Runtime error 0/1003ms3584 KiB
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;

int main()
{
    stack<int> szamok;
    ofstream fout("szamok.txt");
    ifstream fin("be2.txt");
    int h, n;
    int utolso=0, aorb=0;
    fin >> h >> n;
    int horiginal=h;
    string eleje = "";
    while(h>33){
        eleje.push_back('a');

        aorb=1;
        h--;
        if(h>33){
            eleje.push_back('b');
            aorb=2;
        }
        h--;
    }
    if(aorb){
        eleje.pop_back();
    }



    long long a[h][28];
    for(auto& alma:a[1])
    {
        alma=1;
    }
    for(auto& alma:a[0])
    {
        alma=1;
    }
    for(int i=0; i<h; i++){
        a[i][0]=0;
        a[i][27]=0;
    }

    /*for(auto& alma:a[0]){
        cout << alma << " ";
    }
    cout << endl;*/
    for(int i=1; i<h; i++){
            //cout << "a";
        for(int j=1; j<27; j++){
            //cout << a[i-1][j-1] << endl;
            a[i][j]=a[i-1][j-1]+/*a[i-1][j]+*/a[i-1][j+1];
            //cout << "b";
        }
    }
    //cout << '\n';
    //long long kakadudu;
    //long long osszes[28];
    //fill(osszes, osszes+28, 0);
    /*for(auto& alma:a){
            kakadudu=0;
        for(auto& picu:alma){
            fout << picu << " ";
            //kakadudu+=picu;
        }
        fout << endl;
    }*/
    /*for(int i=0; i<h; i++){   //osszes kiszamolasa
        for(int j=0; j<28; j++){
            osszes[j]+=a[i][j];
        }
    }*/

    for(int i=1; i<h; i++){
        for(int j=1; j<27; j++){
            a[i][j]+=a[i-1][j];
            //cout << a[i][j] << " ";
        }
        //cout << endl;
    }




    /*for(auto& apl:osszes){
        cout << apl << " ";
    }*/
    long long osszeg[h][28];
    fill(osszeg[0], osszeg[0]+28, 1);
    osszeg[0][0]=0;
    osszeg[0][27]=0;
    for(int i=1; i<h; i++){
        for(int j=0; j<28; j++){
            osszeg[i][j]=osszeg[i-1][j]+a[i][j];
        }
    }

    /*for(auto& xy:osszeg){
        for(auto& yx:xy){
            cout << yx << " ";
        }
        cout << endl;
    }*/

    //cout << "eleje: " << eleje << endl;
    int x;
    int sor = h-1, i;
    string vege;
    for(int it=0; it<n; it++){
        fin >> x;
        vege.clear();
        utolso=aorb;
        sor=h-1;
        if(utolso==0){
            utolso=1;
            while(x>a[sor][utolso]){
                x-=a[sor][utolso];
                utolso++;
            }
            //vege.push_back(utolso+96);
        }
        else{
            sor=horiginal-1;
            while(sor>33){
                x--;
                sor--;
                vege.push_back('a');
                utolso=1;
                if(sor>33){
                    x--;
                    sor--;
                    vege.push_back('b');
                    utolso=2;
                }
            }
        }

        sor--;
        while(x>0&&sor>=0){
            //cout << "sor: " << sor << endl << "utolso: " << utolso << endl << "x: " << x << endl<< "a[sor][utolso-1] = " << a[sor][utolso] << endl << endl;
            if(x==1){
                //vege.push_back(utolso+96);
                x--;
            }
            else if(a[sor][utolso-1]>=x-1){
                x--;
                vege.push_back(utolso+96);
                //x-=a[sor][utolso];
                utolso--;
            }
            else{
                vege.push_back(utolso+96);
                x-=a[sor][utolso-1];
                x--;
                utolso++;
            }
            sor--;


        }
        vege.push_back(utolso+96);





        cout << /*eleje <<*/ vege << endl;

    }





    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/03ms1716 KiB
2Runtime error0/03ms1884 KiB
3Runtime error0/53ms2208 KiB
4Runtime error0/53ms2372 KiB
5Runtime error0/53ms2308 KiB
6Runtime error0/53ms2560 KiB
7Runtime error0/53ms2520 KiB
8Runtime error0/53ms2716 KiB
9Runtime error0/53ms2668 KiB
10Runtime error0/53ms2996 KiB
11Runtime error0/53ms3264 KiB
12Runtime error0/53ms3156 KiB
13Runtime error0/53ms3096 KiB
14Runtime error0/63ms3368 KiB
15Runtime error0/63ms3324 KiB
16Runtime error0/63ms3584 KiB
17Runtime error0/63ms3540 KiB
18Runtime error0/73ms3524 KiB
19Runtime error0/73ms3520 KiB
20Runtime error0/73ms3516 KiB