比赛 |
2025.1.14 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
编辑字符串 |
最终得分 |
100 |
用户昵称 |
彭欣越 |
运行时间 |
0.645 s |
代码语言 |
C++ |
内存使用 |
6.55 MiB |
提交时间 |
2025-01-14 21:38:42 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int T,n,s10[N],s11[N],s20[N],s21[N],ans;
int f1[N],f2[N];
string s1,s2,t1,t2;
int find1(int x) {
if (f1[x]==x) return x;
return f1[x]=find1(f1[x]);
}
int find2(int x) {
if (f2[x]==x) return x;
return f2[x]=find2(f2[x]);
}
int main () {
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> T;
while (T--) {
memset(s10,0,sizeof(s10));
memset(s11,0,sizeof(s11));
memset(s20,0,sizeof(s20));
memset(s21,0,sizeof(s21));
ans=0;
cin >> n;
cin >> s1;
cin >> s2;
cin >> t1;
cin >> t2;
for (int i=1;i<=n;i++) f1[i]=f2[i]=i;
for (int i=1;i<=n-1;i++) {
if (t1[i-1]=='1'&&t1[i]=='1') f1[find1(i)]=find1(i+1);
if (t2[i-1]=='1'&&t2[i]=='1') f2[find2(i)]=find2(i+1);
}
for (int i=0;i<n;i++) {
if (s1[i]=='0') s10[find1(i+1)]++;
if (s1[i]=='1') s11[find1(i+1)]++;
if (s2[i]=='0') s20[find2(i+1)]++;
if (s2[i]=='1') s21[find2(i+1)]++;
}
for (int i=0;i<n;i++) {
if (s10[find1(i+1)]>0&&s20[find2(i+1)]>0) {
s10[find1(i+1)]--;
s20[find2(i+1)]--;
ans++;
}else if (s11[find1(i+1)]>0&&s21[find2(i+1)]>0) {
s11[find1(i+1)]--;
s21[find2(i+1)]--;
ans++;
}
}
cout << ans <<endl;
}
return 0;
}