芝士代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
int t;
int n;
int s1[maxn], t1[maxn], s2[maxn], t2[maxn];
int lt1[maxn], lt2[maxn];
int cnt1[maxn][2], cnt2[maxn][2];
void take() {
memset(s1, 0, sizeof(s1));
memset(t1, 0, sizeof(t1));
memset(s2, 0, sizeof(s2));
memset(t2, 0, sizeof(t2));
memset(lt1, 0, sizeof(lt1));
memset(lt2, 0, sizeof(lt2));
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
cin>>n;
for (int i = 1; i <= n; i++) scanf("%1d", &s1[i]);
for (int i = 1; i <= n; i++) scanf("%1d", &s2[i]);
for (int i = 1; i <= n; i++) scanf("%1d", &t1[i]);
for (int i = 1; i <= n; i++) scanf("%1d", &t2[i]);
}
void cut() {
int p = 1;
for (int i = 1; i <= n; i++) {
if (t1[i] == 0) {
p++;
continue;
}
else {
lt1[i] = p;
if (s1[i] == 0) cnt1[p][0]++;
else cnt1[p][1]++;
}
}
p = 1;
for (int i = 1; i <= n; i++) {
if (t2[i] == 0) {
p++;
continue;
}
else {
lt2[i] = p;
if (s2[i] == 0) cnt2[p][0]++;
else cnt2[p][1]++;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>t;
while (t--) {
int ans = 0;
take();
cut();
for (int i = 1; i <= n; i++) {
if (t1[i] == 0 && t2[i] == 0) {
if (s1[i] == s2[i]) ans++;
}
else if (t1[i] == 0 && t2[i] != 0) {
if (s1[i] == 0) {
if (cnt2[lt2[i]][0] > 0) {
cnt2[lt2[i]][0]--;
ans++;
}
}
else {
if (cnt2[lt2[i]][1] > 0) {
cnt2[lt2[i]][1]--;
ans++;
}
}
}
else if (t1[i] != 0 && t2[i] == 0) {
if (s2[i] == 0) {
if (cnt1[lt1[i]][0] > 0) {
cnt1[lt1[i]][0]--;
ans++;
}
}
else {
if (cnt1[lt1[i]][1] > 0) {
cnt1[lt1[i]][1]--;
ans++;
}
}
}
}
for (int i = 1; i <= n; i++) {
if (cnt1[lt1[i]][0] > 0 && cnt2[lt2[i]][0] > 0) {
cnt1[lt1[i]][0]--;
cnt2[lt2[i]][0]--;
ans++;
}
else if (cnt1[lt1[i]][1] > 0 && cnt2[lt2[i]][1] > 0){
cnt1[lt1[i]][1]--;
cnt2[lt2[i]][1]--;
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
诡异的是当我把#1和#2的数据下到本地测试后,发现本地答案完全正确,所以到底是什么问题让评测姬这么讨厌我呢。。。