Source Code
#include <bits/stdc++.h>
using namespace std;

/********************* ordered set imp.********************************/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
/********************* macros and typedefs *****************************/
#define all(v) (v.begin()), (v.end())
#define sor(x) sort(all(x))
#define fl(v, d) (memset(v, d, sizeof(v)))
typedef long long ll;
typedef vector<int> vii;
typedef pair<int, int> pii;
void take(vii &v, int n)
{
    v.resize(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
}
/********************* debuging template *******************************/
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define de(x...)                  \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define de(x...)
#endif
/********************* actual sol.***********************************/

#define MOD ll(1e9 + 7)
#define N (const ll)1e5 + 1
vii collect;

inline void solve()
{
    int l, p;
    cin >> l >> p;
    collect.resize((1 << (p - 1)) - 1);

    function<void(int, int, int)> build = [&](int l, int r, int cur)
    {
        if (l > r)
            return;
        int mid = (l + r) >> 1;
        collect[mid] = cur;
        build(l, mid - 1, cur - 1);
        build(mid + 1, r, cur - 1);
    };
    build(0, collect.size() - 1, p - 1);
    for (int i = 0; i <= l; i++)
    {
        for (int j = 0; j < p; j++)
            cout << '-';
        cout << i << "\n";
        if (i == l)
            continue;

        for (int k = 0; k < collect.size(); k++)
        {
            for (int w = 0; w < collect[k]; w++)
            {
                cout << '-';
            }
            cout << "\n";
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}
Copy
Ruler Yazn_yousef
GNU G++17
2 ms
952 KB
Accepted