Source Code
#include <bits/stdc++.h>
using namespace std;
int l, p; 
vector<vector<char>>v;
void build(int dv, int idx, int val) {
	if (idx <0 || idx >= (1<<(p-1)))
		return; 
	for(int i = 0; i<val; ++i)
		v[idx][i] = '-';
	for(int i = val; i<p-1; ++i)
		v[idx][i]= ' ';
		
	if (val == 1)
		return; 
	build(dv/2, dv/2+idx, val-1);
	build(dv/2, idx-dv/2, val-1);
}
int main() {
	cin>>l>>p;
	int x = (1<<(p-1));
	v.resize(x, vector<char>(p-1));
	build(x/2, x/2,p-1);
	for (int i = 0; i<l; ++i) {
		for (int j = 0; j<p; ++j)
			cout<<"-";
		cout<<i;
		for (int j = 0; j<v.size(); ++j) {
			for(auto r : v[j]) {
				cout<<r;
			}
			puts("");
		}
	}
	for (int j = 0; j<p; ++j)
			cout<<"-";
	cout<<l;
	puts("");
	return 0;
}
Copy
Ruler Chicou
GNU G++17
3 ms
328 KB
Wrong Answer