社区讨论

关于刚刚结束的CF D

学术版参与者 7已保存回复 11

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
11 条
当前快照
1 份
快照标识符
@lo32jsdt
此快照首次捕获于
2023/10/23 23:45
2 年前
此快照最后确认于
2023/10/23 23:45
2 年前
查看原帖
考虑先把高位对齐,即利用低位的1去把最高的一个不相同的位对齐,考虑到这个位置必然是1,所以后面的位置都可以通过这一位的1来操作,不影响前面
CPP
#include<bits/stdc++.h>

#define int long long
#define mem(x,y) memset(x,y,sizeof(x))
#define frein freopen("in.in","r",stdin)
#define freout freopen("out.out","w",stdout)

using namespace std;

int read(){
   int s = 0,w = 1;
   char ch = getchar();
   while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
   while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
   return s * w;
}

int t;
int n;
string s1,s2;
int a[20010];
int b[20010];
int c[20010];

vector <int> ans;

void doit2(int x){
	for(int i = 1;i <= n;i ++)c[i] = a[i];
	for(int i = 1;i <= n - x;i ++)a[i] ^= c[i + x]; 
}

void doit(int x){
	for(int i = 1;i <= n;i ++)c[i] = a[i];
	for(int i = x + 1;i <= n;i ++)a[i] = (a[i] ^ c[i - x]);
}

void solve(){
	n = read();
	cin>>s1>>s2;
	s1 = '#' + s1;
	s2 = '#' + s2;
	if(s1 == s2){
		puts("0");
		return ;
	}
	int st1,st2;
	st1 = st2 = 1e18;
	for(int i = 1;i <= n;i ++)a[i] = s1[i] - '0',b[i] = s2[i] - '0';
	for(int i = 1;i <= n;i ++){
		if(st1 == 1e18 && a[i] == 1)st1 = i;
		if(st2 == 1e18 && b[i] == 1)st2 = i;
	} 
	int cnt1,cnt2;
	cnt1 = cnt2 = 0;
//	for(int i = 1;i )
	if(st1 <= st2){
		puts("-1");
		return ;
	}
	ans.clear();
	int ed = -1;
	for(int i = n;i >= 1;i --){
		if(ed == -1 && a[i] == 1){
			ed = i;
			break;
		}
	}
	if(ed == -1){
		puts("-1");
		return ;
	}
//	if(ed == 1 && a[1] != b[1]){
//		puts("-1");
//		return ;
//	}
	st1 = -1;
	for(int i = 1;i <= n;i ++){
		if(st1 == -1 && a[i] == 1){
			st1 = i;
			break;
		}
	}
//	int pos = -1;
//	for(int i = 1;i <= n;i ++){
//		if(pos == -1 && a[i] != b[i]){
//			pos = i;
//			break;
//		}
//	}
//	if(a[pos] != b[pos]){
//		doit2(st1 - pos);
//		ans.push_back(st1 - pos);
//	//	a[1] = b[1];
//	}
	if(st1 != st2){
		doit2(st1 - st2);
		ans.push_back(st1 - st2);
	}
	st1 = -1;
	for(int i = 1;i <= n;i ++){
		if(st1 == -1 && a[i] == 1){
			st1 = i;
			break;
		}
	}
//	for(int i = 1;i <= n;i ++)cout<<a[i]<<" ";
//	puts("-------");
	for(int i = 1;i <= n;i ++){
		if(a[i] == b[i])continue;
		doit(i - st1);
		ans.push_back(-(i - st1));
	}
	printf("%lld\n",ans.size());
	for(int v : ans)printf("%lld ",v);
	puts("");
}

signed main(){
	cin>>t;
	while(t --)solve();
}
WA 3

回复

11 条回复,欢迎继续交流。

正在加载回复...