思路
首先考虑一种连续的染色 ,根据 的值分类讨论。
当余数为 时:可以全部覆盖完。
当余数为 时:怎么样会都剩一个不行,而且如果断开也会有一个不能覆盖。
当余数为 时:怎么样会都剩 个不行,而且如果断开也会有一个不能覆盖。
当余数为 时,会剩 个空位,只需要考虑它们的相对位置。
填完后,应当使得这两个空位的长度模 为 ,剩下的就可以全部覆盖。
code
cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector <int> a(n), b(2);
for (int i = 0; i < n; i ++) cin >> a[i];
if (n % 4 == 0) cout << "Yes\n";
else if (n % 4 == 2) {
for (int i = 0; i < n; i ++) {
if (a[i] && b[(i & 1) ^ 1]) return cout << "Yes\n", 0;
else if (a[i]) b[i & 1] = 1;
}
cout << "No\n";
}else if (n % 4 == 3 || n % 4 == 1) {
if (count(a.begin(), a.end(), 1) == 0) cout << "No\n";
else cout << "Yes\n";
}
return 0;
}