赛时只过了这道,输。
Solution
我们考虑贪心的,形如 ARCRARCR... 的构造。
- 当 时,我们一定可以构造出形如
ARCR这样子首尾相接的串,因此一定能覆盖。 - 当 时,构造出来的串一定形如
ARCRA,也就是11110。然后由于这个东西是循环的,因此只要题目所给的串中存在一组。 - 当 时,构造出来的东西可能是
ARCRAR,也就是111100;也可能是ARCARC,即110110,看起来很麻烦。我们考虑调整这个串的过程,由于每次调整的是一个ARC长度为三,这意味着每次调整都只会把 移动两格,因此这两个0之间只会间隔偶数个1,于是判断一下就做完了。
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
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;
}