dfs40TLE求调
查看原帖
dfs40TLE求调
1272259
cgxd楼主2024/7/25 16:57
#include<bits/stdc++.h>
using namespace std;
int n;
bitset<1000006> bs;
bool check(){
	int cnt00 = 0, cnt01 = 0, cnt10 = 0, cnt11 = 0;
	for(int i = 2; i <= n; ++i){
		if(bs[i - 1] == 0 and bs[i] == 0)
			++cnt00;
        if(bs[i - 1] == 0 and bs[i] == 1)
			++cnt01;
        if(bs[i - 1] == 1 and bs[i] == 0)
			++cnt10;
        if(bs[i - 1] == 1 and bs[i] == 1)
			++cnt11;
	}return cnt00 == cnt01 and cnt01 == cnt10 and cnt10 == cnt11;
}void dfs(int x){
	if(x == n){
		if(check()){
			for(int i = 1; i <= n; ++i)
				printf("%d", bs[i]? 0: 1);
			exit(0);
		}return;
	}bs.set(x);
	dfs(x + 1);
	bs.reset(x);
	dfs(x + 1);
}signed main(){
	scanf("%d", &n);
	dfs(1);
	printf("-1");
	return 0;
}
2024/7/25 16:57
加载中...