题解:P13713 晴天
有一个比较麻烦的做法。
个人想法是先填
考虑使用类似
-
当
x \equiv 0 \pmod{3} 时,使用循环节0, 0, 1 。 -
当
x \equiv 1 \pmod{3} 时,使用循环节1, 0, 0 。 -
当
x \equiv 2 \pmod{3} 时,使用循环节0, 1, 0 。
这个
其中
剩下
-
当
y = 0 时,直接都填0 即可。 -
当
y 为奇数时序列以0, -1 结尾,交替填1, 0, -1 即可。 -
当
y 为偶数时序列以-1, 0 结尾,交替填1, -1, 0 即可。
至于合不合法,直接暴力判断,注意特判
单次时间复杂度
#include <bits/stdc++.h>
#define add(x) ans.emplace_back(x)
using namespace std;
int a[] = {1, -1, 0}, b[] = {1, 0, -1}, c[] = {0, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--) {
int n, x, y;
std::cin >> n >> x >> y;
if (n == 1) {
std::cout << (!x && !y ? 0 : -2) << "\n";
continue;
}
std::vector<int> ans {0};
for (int i = 1; i <= x + 2; ++i)
add(i % 3 == x % 3);
for (int i = 1; i <= y; ++i) add(c[i % 2]);
int v = ans.back() == -1;
for (int i = 0; i < n - y - x - 2; ++i)
if (y == 0) add(0);
else add((v ? b : a)[i % 3]);
if ((int)ans.size() == n + 1) {
for (int i = 1; i <= n; ++i)
std::cout << ans[i] << " \n"[i == n];
} else std::cout << "-2\n";
}
}