题解:AT_arc127_b [ARC127B] Ternary Strings
首先有一个思路,最大值的第一位一定是
我们抛弃第一位,然后剩下的假如说能选出一种暂时方案,我们来看是否能构造出解,我们对于剩下的两个转换一下就行了,所以第
然后就可以构造最小的一组放到
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i <= (int)(r); i++)
#define per(i, l, r) for (int i = (r); i >= (int)(l); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define max(a, b) (!((a) < (b)) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
using i64 = long long;
#define int i64
const int maxn = 1000050, mod = 998244353, B = 700;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, l;
cin >> n >> l;
rep(i, 0, 2) {
rep(j, 0, n - 1) {
int t = j;
cout << 2 - i;
stack<int> stk;
while (t) {
stk.push((t % 3 + i) % 3);
t /= 3;
}
while ((int)stk.size() < l - 1) {
stk.push(i);
}
while (stk.size()) {
cout << stk.top();
stk.pop();
}
cout << "\n";
}
}
return 0;
}