QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#150749#5434. Binary SubstringsTadijaSebezWA 22ms24316kbC++141.7kb2023-08-26 07:32:252023-08-26 07:32:28

Judging History

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

  • [2023-08-26 07:32:28]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:24316kb
  • [2023-08-26 07:32:25]
  • 提交

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<=15){
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2

output:

10

result:

ok meet maximum 3

Test #2:

score: 0
Accepted
time: 1ms
memory: 13840kb

input:

5

output:

01100

result:

ok meet maximum 12

Test #3:

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

input:

1

output:

0

result:

ok meet maximum 1

Test #4:

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

input:

3

output:

100

result:

ok meet maximum 5

Test #5:

score: 0
Accepted
time: 0ms
memory: 13516kb

input:

4

output:

0100

result:

ok meet maximum 8

Test #6:

score: 0
Accepted
time: 1ms
memory: 14308kb

input:

6

output:

011000

result:

ok meet maximum 16

Test #7:

score: 0
Accepted
time: 0ms
memory: 13400kb

input:

7

output:

1101000

result:

ok meet maximum 21

Test #8:

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

input:

8

output:

01101000

result:

ok meet maximum 27

Test #9:

score: 0
Accepted
time: 1ms
memory: 14748kb

input:

9

output:

001101000

result:

ok meet maximum 34

Test #10:

score: 0
Accepted
time: 7ms
memory: 14308kb

input:

10

output:

0011101000

result:

ok meet maximum 42

Test #11:

score: 0
Accepted
time: 9ms
memory: 14100kb

input:

11

output:

00111010000

result:

ok meet maximum 50

Test #12:

score: 0
Accepted
time: 22ms
memory: 13704kb

input:

12

output:

101110010000

result:

ok meet maximum 59

Test #13:

score: -100
Wrong Answer
time: 13ms
memory: 24316kb

input:

200000

output:

000000000000000010111111111111110011111111111111101000000000000000110111111111111100011111111111111011000000000000001110111111111111000011111111111110111000000000000011110111111111110000011111111111101111000000000000111110111111111100000011111111111011111000000000001111110111111111000000011111111110...

result:

wrong answer not meet maximum 19996962255 < 19996962278