53382023-04-25 23:34:25kohumarkKígyózó szavakcpp17Accepted 100/10030ms4608 KiB
#include <iostream>
using namespace std;
int m=4; int c=0;
int h=0; int n=0;
unsigned long long t[26][1000];

void solveend(int x, int i, int a){
	if(x>0){
		if((unsigned)x<=t[i-1][h-a]&&i>0){cout << (char)(i+96); solveend(x-1,i-1,a+1);}
		else{
			cout << (char)(i+98);
			if(i>0) solveend(x-t[i-1][h-a]-1,i+1,a+1);
			else solveend(x-1,i+1,a+1);
		}
	}
		
}

void solve(int x){
	int i=0;
	while(t[i][h-1]<(unsigned)x){
		x-=t[i][h-1]; i++;
	}
	cout << (char)(i+97);
	solveend(x-1,i,2);
}

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> h >> n;
	for(int i=0; i<26; i++) t[i][0]=1;
	for(int i=1; i<25; i++) t[i][1]=3;
	t[0][1]=2; t[25][1]=2;	
	for(int j=2; j<h; j++){
		for(int i=0; i<26; i++){
			if(i==0) t[i][j]=t[i][j-1]+t[i+1][j-1]-t[i+1][j-2];
			else if(i==25) t[i][j]=t[i][j-1]+t[i-1][j-1]-t[i-1][j-2];
			else t[i][j]=t[i][j-1]+t[i-1][j-1]-t[i-1][j-2]+t[i+1][j-1]-t[i+1][j-2];
		}
	}
	for(int i=0; i<n; i++){int x; cin >> x; solve(x); cout << '\n';}
}

SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms2312 KiB
2Accepted0/03ms2456 KiB
3Accepted5/53ms2672 KiB
4Accepted5/53ms2884 KiB
5Accepted5/53ms3128 KiB
6Accepted5/53ms3124 KiB
7Accepted5/53ms3088 KiB
8Accepted5/53ms3364 KiB
9Accepted5/513ms3412 KiB
10Accepted5/510ms3740 KiB
11Accepted5/516ms3732 KiB
12Accepted5/517ms3960 KiB
13Accepted5/530ms4264 KiB
14Accepted6/68ms3992 KiB
15Accepted6/616ms4296 KiB
16Accepted6/610ms4392 KiB
17Accepted6/69ms4256 KiB
18Accepted7/710ms4272 KiB
19Accepted7/729ms4608 KiB
20Accepted7/712ms4508 KiB