12722022-03-29 15:32:23FulopMateKígyózó szavakcpp14Runtime error 30/1003ms4132 KiB
#include <bits/stdc++.h>

using namespace std;

//#define __TEST_CASE_TEXT
#define __TEST_CASE_BEFORE "Case #"
#define __TEST_CASE_AFTER ": "

#define ll long long
#define all(c) (c).begin(), (c).end()
#define MIN(a, b) ((a) = min((a), (b)))
#define MAX(a, b) ((a) = max((a), (b)))

const ll MOD = 1e9+7;
const int abc = 'z'-'a'+1;

vector<ll> v[abc];

string ans;

void p(ll n, int maxh, int last = -2){
    if(n == 0){
        ans = "";
        return;
    }
    int j = 0;
    if(last == -2){
        while(v[j][maxh] < n || j == last){
            if(j == last){
                j++;
                continue;;
            }
            n -= v[j][maxh];
            j++;
        }
    } else {
        if(last == 0){
            j = 1;
        } else {
            j = last-1;
            if(v[j][maxh] < n){
                n -= v[j][maxh];
                j = last+1;
            }
        }
    }
    p(n-1, maxh-1, j);
    ans += 'a'+j;
}

void solve(){
    int n, m; cin>>n>>m;
    for(auto &i: v){i.assign(n+1, 0); i[1] = 1;}
    for(int i = 2; i <= n; i++){
        v[0][i] = v[1][i-1];
        v[abc-1][i] = v[abc-2][i-1];
        for(char j = 1; j < abc-1; j++){
            v[j][i] = v[j-1][i-1] + v[j+1][i-1];
        }
    }
    for(int j = 0; j < abc; j++){
        for(int i = 2; i <= n; i++){
            v[j][i] += v[j][i-1];
        }
    }
    while(m--){
        ll a; cin>>a;
        p(a, n);
        reverse(all(ans));
        cout<<ans<<endl;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int _t;
    _t = 1;
    for(int _i = 0; _i < _t; _i++){
        #ifdef __TEST_CASE_TEXT
        cout<<__TEST_CASE_BEFORE<<_i+1<<__TEST_CASE_AFTER;
        #endif
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/100
1Accepted0/03ms1952 KiB
2Accepted0/01ms1988 KiB
3Accepted5/51ms1992 KiB
4Accepted5/52ms1992 KiB
5Accepted5/52ms2008 KiB
6Accepted5/53ms2000 KiB
7Accepted5/52ms1992 KiB
8Accepted5/53ms2036 KiB
9Runtime error0/52ms3764 KiB
10Runtime error0/52ms3756 KiB
11Runtime error0/52ms3824 KiB
12Runtime error0/52ms3864 KiB
13Runtime error0/52ms4068 KiB
14Runtime error0/62ms3788 KiB
15Runtime error0/62ms3892 KiB
16Runtime error0/62ms3832 KiB
17Runtime error0/62ms3836 KiB
18Runtime error0/72ms3852 KiB
19Runtime error0/73ms4132 KiB
20Runtime error0/72ms3888 KiB