题解:CF2029B Replacement
洛谷CF2029B || CodeForces 2029 B
题意翻译
给出一个长度为 NO 并结束,然后将
当所有 YES。
思路
如果当前 NO。
在第 NO,否则必然可以完成所有操作并输出 YES。
时间复杂度:
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
using namespace std;
using ll = long long;
const int _N = 1e5 + 5;
void solve() {
int n; cin >> n;
string s, t; cin >> s >> t;
int cnt0 = count(all(s), '0'), cnt1 = n - cnt0;
for (int i = 0; i < n - 1; i++) {
if (cnt0 == 0 || cnt1 == 0) {
cout << "NO" << '\n';
return;
}
if (t[i] == '1') cnt0--;
else cnt1--;
}
cout << "YES" << '\n';
}
int main() {
int T; cin >> T;
while (T--) {
solve();
}
}