社区讨论
0pts样例过了求条玄关
P11361[NOIP2024] 编辑字符串参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mj2i660r
- 此快照首次捕获于
- 2025/12/12 14:45 3 个月前
- 此快照最后确认于
- 2025/12/14 08:40 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
string s1,s2,t1,t2;
int n,id1[N],id2[N],n1,n2;
struct node {
int c0,c1;
} a[N],b[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--) {
cin>>n;
cin>>s1>>s2>>t1>>t2;
n1=n2=0;
for(int i=0; i<n; i++) {
if(t1[i]=='0'||!i||t1[i-1]=='0') {
a[++n1]= {0,0};
if(s1[i]=='0') a[n1].c0++;
else a[n1].c1++;
} else {
if(s1[i]=='0') a[n1].c0++;
else a[n1].c1++;
}
id1[i]=n1;
}
for(int i=0; i<n; i++) {
if(t2[i]=='0'||!i||t2[i-1]=='0') {
b[++n2]= {0,0};
if(s2[i]=='0') b[n2].c0++;
else b[n2].c1++;
} else {
if(s2[i]=='0') b[n2].c0++;
else b[n2].c1++;
}
id2[i]=n2;
}
int cnt=0;
for(int i=0;i<n;i++){
if(a[id1[i]].c1&&b[id2[i]].c1){
a[id1[i]].c1--;
b[id2[i]].c1--;
cnt++;
}
else if(a[id1[i]].c0&&b[id2[i]].c0){
a[id1[i]].c0--;
b[id2[i]].c0--;
cnt++;
}
else{
if(s1[i]=='0') a[id1[i]].c0--;
else a[id1[i]].c1--;
if(s2[i]=='0') b[id2[i]].c0--;
else b[id2[i]].c1--;
}
}
cout<<cnt<<"\n";
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...