Source Code
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int l, p;
vector<string> bars;

void print(int i){
    if( i == 1 ){
        cout << "-\n";
    } else {
        print(i-1);
        cout << bars[i] << '\n';
        print(i-1);
    }
} 

int main(){
    cin >> l >> p;

    bars.resize(p+1);
    for(int i = 1; i <= p; ++i)
        bars[i] = bars[i-1] + '-';

    for(int i = 0; i < l; ++i){
        cout << bars[p] << i << '\n';
        print(p-1);
    }
    cout << bars[p] << l << endl;

	return 0;
}
Copy
Ruler Trainee
GNU G++17
933 ms
262.1 MB
Memory Limit Exceeded