QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150748#5434. Binary SubstringsTadijaSebezWA 4ms14192kbC++141.7kb2023-08-26 07:31:282023-08-26 07:31:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-26 07:31:31]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:14192kb
  • [2023-08-26 07:31:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N=400050;
vector<int> E[N];
int ptr[N];
vector<int> cyc;
void DFS(int u){
	while(true){
		if(ptr[u]==E[u].size()){
			cyc.pb(u);
			return;
		}
		DFS(E[u][ptr[u]++]);
	}
}

void Euler(int sz){
	for(int mask=0;mask<(1<<sz);mask++){
		E[mask].pb(mask>>1);
		E[mask].pb((mask>>1)|(1<<(sz-1)));
	}
	DFS(0);
}

string Solve(int sz,int n){
	vector<int> ord;
	vector<int> next(1<<sz,0);
	for(int i=0;i+1<cyc.size();i++){
		ord.pb((cyc[i]<<1)|(cyc[i+1]&1));
	}
	for(int i=0;i<ord.size();i++){
		next[ord[i]]=ord[(i+1)%ord.size()];
	}
	vector<int> p(1<<sz,0);
	for(int mask=0;mask<(1<<sz);mask++){
		p[mask]=next[mask]^1;
	}
	vector<bool> was(1<<sz,false);
	vector<int> sol;
	n-=1<<sz;
	n-=sz-1;
	for(int i=0;i<(1<<sz);i++){
		int mask=ord[i];
		sol.pb(mask);
		if(!was[mask] && n>0){
			while(!was[mask]){
				was[mask]=true;
				sol.pb(p[mask]);
				mask=p[mask];
				n--;
				if(n==0)break;
			}
		}
	}
	string ans="";
	for(int i=0;i<sz-1;i++){
		ans+='0'+(sol[0]>>(sz-1-i)&1);
	}
	for(int mask:sol){
		ans+='0'+(mask&1);
	}
	return ans;
}

void Brute(int n){
	int ans=0;
	string best="";
	for(int mask=0;mask<(1<<n);mask++){
		string now="";
		for(int i=0;i<n;i++){
			now+='0'+(mask>>i&1);
		}
		set<string> sub;
		for(int l=0;l<n;l++){
			for(int r=l;r<n;r++){
				sub.insert(now.substr(l,r-l+1));
			}
		}
		if(ans<sub.size()){
			ans=sub.size();
			best=now;
		}
	}
	printf("%s\n",best.c_str());
}

int main(){
	int n;
	scanf("%i",&n);
	if(n<=4){
		Brute(n);
		return 0;
	}
	int sz=1;
	while((1<<(sz+1))+sz<=n)sz++;

	Euler(sz-1);
	string ans=Solve(sz,n);
	printf("%s\n",ans.c_str());
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 14192kb

input:

2

output:

10

result:

ok meet maximum 3

Test #2:

score: 0
Accepted
time: 3ms
memory: 12960kb

input:

5

output:

01100

result:

ok meet maximum 12

Test #3:

score: 0
Accepted
time: 4ms
memory: 12960kb

input:

1

output:

0

result:

ok meet maximum 1

Test #4:

score: 0
Accepted
time: 4ms
memory: 13508kb

input:

3

output:

100

result:

ok meet maximum 5

Test #5:

score: 0
Accepted
time: 2ms
memory: 13104kb

input:

4

output:

0100

result:

ok meet maximum 8

Test #6:

score: -100
Wrong Answer
time: 4ms
memory: 14136kb

input:

6

output:

010100

result:

wrong answer not meet maximum 14 < 16