QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#150746#5434. Binary SubstringsTadijaSebezWA 4ms14492kbC++141.5kb2023-08-26 07:28:172023-08-26 07:28:18

Judging History

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

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

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;
}

int main(){
	int n;
	scanf("%i",&n);
	if(n<=4){
		if(n==1)printf("0\n");
		if(n==2)printf("01\n");
		if(n==3)printf("010\n");
		if(n==4)printf("0100\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: 1ms
memory: 13280kb

input:

2

output:

01

result:

ok meet maximum 3

Test #2:

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

input:

5

output:

01100

result:

ok meet maximum 12

Test #3:

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

input:

1

output:

0

result:

ok meet maximum 1

Test #4:

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

input:

3

output:

010

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: 0ms
memory: 13140kb

input:

6

output:

010100

result:

wrong answer not meet maximum 14 < 16