53352023-04-25 23:15:51kohumarkKígyózó szavakcpp17Wrong answer 30/1004ms4560 KiB
#include <iostream>
using namespace std;
int m=4; int c=0;
int h=0; int n=0;
long long t[26][1000];

void solveend(int x, int i, int a){
	if(x>0){
		if(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]<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];
			//cout << t[i][j] << '\n';
		}
	}
	for(int i=0; i<n; i++){int x; cin >> x; solve(x); cout << '\n';}
}

SubtaskSumTestVerdictTimeMemory
base30/100
1Accepted0/03ms2312 KiB
2Accepted0/03ms2552 KiB
3Accepted5/53ms2668 KiB
4Accepted5/53ms2884 KiB
5Accepted5/53ms3004 KiB
6Accepted5/53ms3140 KiB
7Accepted5/53ms3344 KiB
8Accepted5/53ms3488 KiB
9Wrong answer0/53ms3648 KiB
10Wrong answer0/53ms3636 KiB
11Wrong answer0/53ms3744 KiB
12Wrong answer0/53ms3960 KiB
13Wrong answer0/54ms4124 KiB
14Wrong answer0/63ms3884 KiB
15Wrong answer0/63ms4200 KiB
16Wrong answer0/63ms4104 KiB
17Wrong answer0/63ms4252 KiB
18Wrong answer0/73ms4180 KiB
19Wrong answer0/73ms4560 KiB
20Wrong answer0/73ms4396 KiB