Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> build(int L) {
    vector<int> cur;
    cur.push_back(L);
    for (int i=L;i>=2;i--) {
        vector<int> newV;
        for (auto x:cur){
            if (x==i) {
                newV.push_back(x-1);
                newV.push_back(x);
                newV.push_back(x-1);
            } else newV.push_back(x);
        }
        cur = newV;
    }
    return cur;
}
void printVec(vector<int> v) {
    for (auto x:v) {
        if (x) {
            while(x--) cout<<'-';
            cout<<endl;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    int l, p;
    cin>>l>>p;
    vector<int> v = build(p-1);
    for (int i=0;i<l;i++) {
        for (int j=0;j<p;j++) cout<<'-';
        cout<<i<<endl;
        printVec(v);
    }
    for (int i=0;i<p;i++)cout<<'-';
    cout<<l<<endl;
}
Copy
Ruler RedNextCentury
GNU G++17
12 ms
916 KB
Accepted