题解:CF1725H Hot Black Hot White
考虑将
所以原式就变成了
然后由于在模
于是把他们一一列举出来:
| 1 | ||
我们发现对于
设
那么只要
否则对于
也就是
又由于
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
bool st[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
int cnt = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] % 3 == 0)
st[i] = true, ++cnt;
}
if (cnt > n / 2) {
memset(st, false, sizeof(st));
cnt = 0;
for (int i = 1; i <= n; ++i)
if (a[i] % 3 == 1 || a[i] % 3 == 2) {
++cnt;
st[i] = true;
}
for (int i = 1; i <= n; ++i) if (!st[i] && cnt < n / 2) {
++cnt;
st[i] = true;
}
puts("2");
for (int i = 1; i <= n; ++i) printf("%d", st[i]);
return 0;
}
for (int i = 1; i <= n; ++i)
if (!st[i] && cnt < n / 2) {
++cnt;
st[i] = true;
}
puts("0");
for (int i = 1; i <= n; ++i) printf("%d", st[i]);
return 0;
}