99152024-03-18 15:52:07111Kígyózó szavakcpp17Accepted 100/1008ms3760 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int mem[26][1001];

int calc(int c,int n){
	if(c<0||c>=26)return 0;
	if(n==1)return 1;
	if(mem[c][n])return mem[c][n];
	return mem[c][n]=min(1+calc(c-1,n-1)+calc(c+1,n-1),(int)1e18);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
    int H,N;
    cin>>H>>N;
    for(int i=0;i<N;i++){
		int x;
		cin>>x;
		string s;
		int y=0;
		char c='a';
		while((y+=calc(c-'a',H))<x)c++;
		s+=c;
		x-=y-calc(c-'a',H);
		x--;
		while(x>0){
			x--;
			if(c=='a'){
				c++;
			}
			else if(calc(c-1-'a',H-s.size())>x){
				c--;
			}
			else{
				x-=calc(c-1-'a',H-s.size());
				c++;
			}
			s+=c;
		}
		cout<<s<<'\n';
    }
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1712 KiB
2Accepted0/03ms2096 KiB
3Accepted5/53ms2308 KiB
4Accepted5/53ms2516 KiB
5Accepted5/53ms2600 KiB
6Accepted5/53ms2744 KiB
7Accepted5/53ms2824 KiB
8Accepted5/53ms2964 KiB
9Accepted5/54ms3408 KiB
10Accepted5/54ms3580 KiB
11Accepted5/56ms3664 KiB
12Accepted5/56ms3704 KiB
13Accepted5/58ms3760 KiB
14Accepted6/64ms3520 KiB
15Accepted6/66ms3672 KiB
16Accepted6/64ms3688 KiB
17Accepted6/64ms3532 KiB
18Accepted7/74ms3568 KiB
19Accepted7/78ms3756 KiB
20Accepted7/74ms3576 KiB