I want to share my construct method for 2092D - Mishkin Energizer. I think it is easy to understand and enlightening.
The first thing that caught my eye was this $$$2n$$$ constraint. At the same time, the problem asks us to make the number of the three letters equal. I'm going to use $$$\texttt{A}$$$,$$$\texttt{B}$$$,$$$\texttt{C}$$$ instead of $$$\texttt{L}$$$,$$$\texttt{I}$$$,$$$\texttt{T}$$$ for the sake of clarity.
Suppose that we have $$$\texttt{A}$$$ with the amount of $$$a$$$, and $$$\texttt{B}$$$ with the amount of $$$b$$$, $$$\texttt{C}$$$ with the amount of $$$c$$$. So $$$a+b+c=n$$$. I found that if we make them all appear $$$n$$$ times in the last sequence, the number of operations we need is exactly $$$2n$$$.
I like it because it havs the beauty of circular symmetry which fits my gut. Let's think about how do we get there.
I don't like too complicated operation because it always lead to classification discussion. In contests that require speed, classification discussions are often error-prone and time-wasteful. For a d2D, I tend to organize a complete idea before writing code.
Suppose we had one $$$\texttt{AB}$$$. I hope it can create enough of what I want.
First of all, we can only insert $$$\texttt{C}$$$ into it and it becomes $$$\texttt{ACB}$$$. What should we do? I don't want to destroy the structure of $$$\texttt{AB}$$$ so I insert another $$$\texttt{A}$$$ between $$$\texttt{C}$$$ and $$$\texttt{B}$$$. Now it is $$$\texttt{ACAB}$$$. Can we have more $$$\texttt{CA}$$$? Of course we can. If we repeat the operation above, we will get $$$\texttt{ACACACACACACACAB}$$$.
In other words, we can use a $$$\texttt{AB}$$$ to generate enough $$$\texttt{CA}$$$. This is a major breakthrough in our thinking.
Let's go back and think about the limitations of the problem. If we want to get all of the letter appear $$$n$$$ times, we need create $$$(n - a)$$$ $$$\texttt{A}$$$, $$$(n - b)$$$ $$$\texttt{B}$$$ and $$$(n - c)$$$ $$$\texttt{C}$$$. If we can If we were free to create $$$\texttt{CA}$$$, $$$\texttt{AB}$$$ and $$$\texttt{BC}$$$, we can manage to do it! That's because if we create $$$x$$$ $$$\texttt{BC}$$$, $$$y$$$ $$$\texttt{CA}$$$ and $$$z$$$ $$$\texttt{AB}$$$, just need:
so
because $$$a+b+c=n$$$.
Right now, we're just one step away from success which is to generate enough $$$\texttt{BC}$$$ and $$$\texttt{AB}$$$. When we get $$$\texttt{ACACACACACACACAB}$$$, we will find it easy to get $$$\texttt{ABCACACACACACACAB}$$$ and $$$\texttt{ACBCACACACACACACAB}$$$ next. It seems that $$$\texttt{AC}$$$ can create $$$\texttt{CB}$$$ which makes it become $$$\texttt{ACBC}$$$ and protect $$$\texttt{AC}$$$ to create more $$$\texttt{CB}$$$. In the same way, $$$\texttt{BA}$$$ can be generated infinitely by $$$\texttt{AC}$$$. Now we can solve this problem.
In the process of implementation, as soon as we meet two adjacent and different letters, we let the left be $$$\texttt{A}$$$ and the right be $$$\texttt{B}$$$. Through the above analysis, we can construct a scheme that conforms to the constraints. If we failed to meet two adjacent and different letters, it means that all of the letters are the same so we can't make any operation at all, which lead to the output of $$$\texttt{-1}$$$.
My code in the contest:
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 2e5 + 10;
void solve() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
std::map<char, int> cnt;
for (int i = 0; i < n; i++) {
cnt[s[i]]++;
}
std::vector<int> op;
for (int i = 0; i + 1 < n; i++) {
if (s[i] != s[i + 1]) {
for (int c = 0; c < 2 * cnt[s[i + 1]]; c++) {
op.push_back(i + c);
}
for (int c = 0; c < 2 * cnt[s[i]]; c++) {
op.push_back(i + 2 * cnt[s[i + 1]]);
}
char tar = '0';
std::string tmp = "LIT";
for (int x = 0; x < 3; x++) {
if (tmp[x] != s[i] && tmp[x] != s[i + 1]) {
tar = tmp[x];
break;
}
}
for (int c = 0; c < 2 * cnt[tar]; c++) {
op.push_back(i + c);
}
std::cout << 2 * n << '\n';
for (const auto &num : op) {
std::cout << num + 1 << '\n';
}
return;
}
}
std::cout << -1 << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}



