Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI acos(-1)
#define fr first
#define se second
#define int long long
const int MAXN = 2e5+7;
const int MOD = 1e9 + 7;
typedef tree<int , null_type ,  less<int> , rb_tree_tag ,
	tree_order_statistics_node_update> os;
vector<int> solve(int l, int r){
	if (l == 1 and r == 1) {
		vector<int> z = {1};
		return z;
	}
	else if (l == 1 or r == 1){
        vector<int> z = {l,r};
        return z;
	}
	vector<int> v = {l,r};
	int t = min(l,r);
	v.insert(v.begin() + 1, t - 1);
	vector<int> a = solve(v[0], v[1]);
	vector<int> b = solve(v[1], v[2]);
	vector<int> ans;
	for (auto k: a)
		ans.push_back(k);
	for (auto k : b)
		ans.push_back(k);
	return ans;

}

signed main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int l,p;
	cin >> l >> p;
	vector<int> res = solve(p,p);

	vector<int> v;
	v.push_back(p);
	for (int i = 1 ; i < res.size() - 1 ; i++){
		if (res[i] == v.back()) continue;
		else v.push_back(res[i]);
	}
	for (int i = 0 ; i < l ; i++){
		
		for (int j = 0 ; j < v.size() ; j++){
			int k = v[j];
			while(k-- > 0){
				cout << "-";
			}
			if (j==0) cout << i;
			cout << endl;

		}
	}
	while(p--){
		cout << "-";
	}
	cout << l << endl;
	/*




	*/


}
Copy
Ruler MysteRrion
GNU G++17
13 ms
1.0 MB
Accepted